Cockatrice/libcockatrice_models/libcockatrice/models/database
BruebachL 4980f88a7a
[CardDB] Sort power/toughness without splitting every comparison (#7607)
* [CardDB] Sort power/toughness without splitting every comparison

When the card database is sorted by the P/T column, lessThan() runs
O(n log n) times over the whole view, and each call split both strings
into a QStringList ("power/toughness") and then read the two elements
back. For the roughly 36k cards in the database that is millions of
list and string allocations, all for a value that contains at most one
separator.

The comparator now locates the single '/' with indexOf and passes the
two halves as QStringView to lessThanNumerically(), which is changed
from QString to QStringView. The numeric parsing, the "1+*" fallback and
the locale-aware tie-break are unchanged, and strings with no separator
or more than one still fall through to the plain string comparison,
exactly as split()-based size checks did before.

lessThanNumerically() also initializes its two bool out-parameters; they
were declared uninitialized, which only worked because toFloat() always
assigns them.

Compared old and new comparator over a corpus of 2024 power/toughness
strings (4096576 ordered pairs, including malformed values): zero
differences. Full build and ctest (628 tests) pass.

* Extract well-formedness checks in P/T comparator

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-10-23 10:34:13 +02:00
..
card [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
card_set [CardDB] Reload after the first run enables all sets without freezing startup (#7470) 2026-10-13 06:29:16 +02:00
token [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
card_database_display_model.cpp [CardDB] Sort power/toughness without splitting every comparison (#7607) 2026-10-23 10:34:13 +02:00
card_database_display_model.h [CardDB] Sort power/toughness without splitting every comparison (#7607) 2026-10-23 10:34:13 +02:00
card_database_model.cpp [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
card_database_model.h [Tooling] Apply include-what-you-use across the tree (#7396) 2026-10-08 11:13:50 +02:00
CMakeLists.txt [Build] Extend PCH to libraries and grow IWYU-driven header sets (#7456) 2026-10-11 15:07:30 +02:00