Performance improvement
Thiago Macieira
thiago at kde.org
Mon May 26 01:18:16 BST 2025
On Thursday, 22 May 2025 11:21:03 Central Daylight Time Igor Mironchik wrote:
> inline long long int
> skipSpaces(long long int i, const QString &line)
> {
> return skipIf(i, line, [](const QChar &ch){ return ch.isSpace(); });
> }
>
> Do you know a way to optimize it?
In addition to what other people have said, the problem here is that your
predicate depends on Unicode attributes. Even though the set is limited and
closed, it isn't known at compile time. In fact, considering Qt can be updated
without the application, it will only be known at runtime.
Specifically for spaces, maybe you should consider QString::trimmed(), which
can access the unicode tables directly and thus avoids the overhead of a
function call.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Principal Engineer - Intel Platform & System Engineering
More information about the kde-devel
mailing list