Make zone-name part of date-time parsing a little faster

QDateTimeParser::findTimeZoneName()'s invalidZoneNameCharacter() check
was using QLatin1String::contains(QChar), which converts the Latin-1
string to UTF-16 on each call, despite having pre-checked that the
QChar is ASCII. So use memchr() instead.

Change-Id: I011e2b4ba3be20711fc5005f62e4f9f6a392dd16
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Edward Welbourne 2021-04-19 13:21:29 +02:00
parent c36f18b449
commit 7c65935810

View File

@ -1734,8 +1734,8 @@ QDateTimeParser::findTimeZoneName(QStringView str, const QDateTime &when) const
// Collect up plausibly-valid characters; let QTimeZone work out what's // Collect up plausibly-valid characters; let QTimeZone work out what's
// truly valid. // truly valid.
const auto invalidZoneNameCharacter = [] (const QChar &c) { const auto invalidZoneNameCharacter = [] (const QChar &c) {
return c.unicode() >= 127u const auto cu = c.unicode();
|| (!c.isLetterOrNumber() && !QLatin1String("+-./:_").contains(c)); return cu >= 127u || !(memchr("+-./:_", char(cu), 6) || c.isLetterOrNumber());
}; };
int index = std::distance(str.cbegin(), int index = std::distance(str.cbegin(),
std::find_if(str.cbegin(), str.cend(), invalidZoneNameCharacter)); std::find_if(str.cbegin(), str.cend(), invalidZoneNameCharacter));