Cockatrice/libcockatrice_utility/libcockatrice/utility
BruebachL f4b4365464
[Search] Stop allocating per card in card-name completion (#7604)
* [Search] Stop allocating per card in card-name completion

CardSearchModel::updateSearchResults() runs on every textEdited()
signal, walks the whole card database and runs Levenshtein against every
matching name. Three costs dominated that path:

1. Every candidate built a QStringList of its searchable names, then
   lowercased each name into another QString, only to break out of the
   loop after the first hit.
2. The sort comparator called sortableName() for each comparison, which
   re-fetched the name (QMap lookup plus QString construction) O(n log n)
   times.
3. levenshteinDistance() allocated a full len1 x len2 vector of vectors.

The search model now lowercases the one name it tests directly, stores
the tie-breaking name length once per result, and the comparator only
compares integers. levenshteinDistance() uses the standard two-row
formulation: same result, O(len2) memory instead of O(len1*len2), with
early exits for empty and equal strings.

FilterString query closures get the same treatment:
- Set queries iterate the set map directly instead of materializing
  keys()/values() lists for every card.
- Rarity queries iterate printings in place instead of copying them into
  a QList<PrintingInfo> first.
- Power/toughness split the string with indexOf and compare QStringViews
  instead of allocating a QStringList.
- Field queries do one hash lookup instead of contains() followed by
  value().
- Color queries bind the colors string by reference instead of copying.

Verified with filter_string_test (42 tests) and a full client build.

* [Search] Address review comments

- Use std::any_of/std::none_of over the set map's key/value iterators
  instead of hand-rolled loops.
- Extract the name matching into matchingLowercaseName() returning
  std::optional<QString>.
- Reuse the matched name's length for the distance tie-break instead of
  looking the name up again, removing one getLocalizedName() call per card.
- Take the color strings by value; the getters already return by value.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-10-23 11:23:04 +02:00
..
card_ref.h [DeckList] Move metadata into struct (#6380) 2025-11-30 13:09:09 +01:00
clamped_arithmetic.h Unify counter clamp arithmetic into shared addClamped() helper (#7009) 2026-06-28 16:10:57 -07:00
color.h [Game][Counters] Split counters into AbstractCounter (graphics) and CounterState (logic) (#6917) 2026-05-21 20:16:28 +02:00
counter_limits.h Split trice_limits.h into dedicated headers (#7025) 2026-06-29 14:37:52 -07:00
cryptoutil.cpp [Security] Add challenge-response auth with scrypt verifiers and stop storing plaintext passwords (#7193) 2026-10-16 22:52:26 +02:00
cryptoutil.h [Security] Add challenge-response auth with scrypt verifiers and stop storing plaintext passwords (#7193) 2026-10-16 22:52:26 +02:00
days_years_between.h [Room][UserList] Introduce style delegate (#6981) 2026-06-26 20:52:24 -04:00
dice_limits.h Split trice_limits.h into dedicated headers (#7025) 2026-06-29 14:37:52 -07:00
expression.cpp [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
expression.h Turn Card, Deck_List, Protocol, RNG, Network (Client, Server), Settings and Utility into libraries and remove cockatrice_common. (#6212) 2025-10-09 07:36:12 +02:00
levenshtein.cpp [Search] Stop allocating per card in card-name completion (#7604) 2026-10-23 11:23:04 +02:00
levenshtein.h Standardize Doxygen documentation (#6885) 2026-05-21 22:58:07 +02:00
local_server_name.h [Client] Improve card database update visibility (#7458) 2026-10-09 11:07:48 +02:00
macros.h Turn Card, Deck_List, Protocol, RNG, Network (Client, Server), Settings and Utility into libraries and remove cockatrice_common. (#6212) 2025-10-09 07:36:12 +02:00
passwordhasher.cpp [Security] Add challenge-response auth with scrypt verifiers and stop storing plaintext passwords (#7193) 2026-10-16 22:52:26 +02:00
passwordhasher.h [Security] Add challenge-response auth with scrypt verifiers and stop storing plaintext passwords (#7193) 2026-10-16 22:52:26 +02:00
peglib.h Update peglib to v1.16.0 (#7134) 2026-08-17 22:52:30 +02:00
playmat_params.h [Game] Playmats (#7101) 2026-08-21 10:40:49 +02:00
qt_utils.h Add subtype breakdown counter for card selection (#6923) 2026-06-27 15:53:21 -07:00
report_categories.cpp [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
report_categories.h [Server/Client] Unify report categories (#7345) 2026-09-24 18:37:54 +02:00
server_rate_limiter.cpp [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
server_rate_limiter.h [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
string_limits.h [Server/Client/Protocol] Reporting users + moderation queue functionality (#7091) 2026-08-21 15:00:13 +02:00
translation_loader.cpp [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
translation_loader.h [Translations] Load Qt's own translations and build ours with the binary (#7384) 2026-10-03 15:04:30 +02:00
user_data_backup.cpp [Installer][Client] Back up user data before old uninstallers can delete it (#7503) 2026-10-16 22:05:42 +02:00
user_data_backup.h [Installer][Client] Back up user data before old uninstallers can delete it (#7503) 2026-10-16 22:05:42 +02:00
warning_categories.cpp [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
warning_categories.h [Server/Client/Protocol] Reporting users + moderation queue functionality (#7091) 2026-08-21 15:00:13 +02:00
zone_names.h Refactor zone names (#6686) 2026-03-12 00:34:05 +01:00