diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2025-07-29 15:16:39 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-08-01 15:46:03 +0000 |
| commit | 4f3a8a8d68ce804f5d999559ccf11a42a79e3f8f (patch) | |
| tree | 66d3f211d3940b1f8690fb7770f3db98b0962f56 /src/gui/doc/snippets/code | |
| parent | f0f45d1bcd4b1f34b7f47fb9f0458c38d93e6da3 (diff) | |
moc: rewrite mergeStringLiterals() to avoid O(N²) algorithm
The old code called QList::erase(it, it) in a loop; which causes
quadratic behavior.
Fix by writing a std::unique-inspired merge algorithm that works in
linear time, at the cost of merging only pairs of consecutive
STRING_LITERALs. The old code tried to merge maximal sequences of
adjacent STRING_LITERALs. This should not make much of a difference,
since QByteArray grows geometrically, so appends (and insert at end -
1 is almost append) take amortized linear time in the final size of
the result.
Symbol is a QByteArray version of QStringRef (i.e. a cheap substring:
string, from, len), except with individual copies of the underlying
string, so make sure to rid Symbol::lex of non-lexem() data before
merging. Aurélien reports that `lex` may contain a whole file, so this
is an important step.
Aurélien reports a 6x speedup on one of his benchmark files.
Amends 0c9d1f99dac5c118d49e7f2b04f70eae3ba7b837.
Reported-by: Aurélien Brooke <aurelien@bahiasoft.fr>
Done-with: Aurélien Brooke <aurelien@bahiasoft.fr>
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I1093a43c3727fde1785795b1aac7417be011bad8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Aurélien Brooke <aurelien@bahiasoft.fr>
Diffstat (limited to 'src/gui/doc/snippets/code')
0 files changed, 0 insertions, 0 deletions
