QLocale: improve speed of 'applyIntegerFormatting()'
This patch reduced the runtime of "QString::number(12345678)" from 119ns to 84ns in one measurement. It removes one copy of a QString into a local lambda function, it adds a std::move on return, removing another QString instantiation and it removes the usage of StringBuilder on return, which created another QString. Task-number: QTBUG-87330 Change-Id: Ia37e314353c354ae04402cd482d0f7aeabbfc0cb Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
4c5c4c6d1c
commit
e6cba05b66
|
|
@ -3578,7 +3578,7 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
|
|||
const auto digitWidth = zero.size();
|
||||
const auto digitCount = numStr.length() / digitWidth;
|
||||
|
||||
const auto basePrefix = [numStr, zero, base, flags] () -> QStringView {
|
||||
const auto basePrefix = [&] () -> QStringView {
|
||||
if (flags & ShowBase) {
|
||||
const bool upper = flags & UppercaseBase;
|
||||
if (base == 16)
|
||||
|
|
@ -3589,9 +3589,9 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
|
|||
return zero;
|
||||
}
|
||||
return {};
|
||||
};
|
||||
}();
|
||||
|
||||
const QString prefix = signPrefix(negative, flags) + basePrefix();
|
||||
const QString prefix = signPrefix(negative, flags) + basePrefix;
|
||||
// Count how much of width we've used up. Each digit counts as one
|
||||
int usedWidth = digitCount + prefix.size();
|
||||
|
||||
|
|
@ -3625,7 +3625,10 @@ QString QLocaleData::applyIntegerFormatting(QString &&numStr, bool negative, int
|
|||
numStr.prepend(zero);
|
||||
}
|
||||
|
||||
return prefix + (flags & CapitalEorX ? std::move(numStr).toUpper() : numStr);
|
||||
QString result(flags & CapitalEorX ? std::move(numStr).toUpper() : std::move(numStr));
|
||||
if (prefix.size())
|
||||
result.prepend(prefix);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in New Issue