Unix fallbackLocale(): use QString::tokenize() rather than split()

We only want the first entry, so avoid all the allocations of
split()ing and just look at the first.

Change-Id: I81beee1856608c932254213f2971fc37bc457c41
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2021-08-31 17:17:33 +02:00
parent 121fddcf5a
commit 0108275b0c

View File

@ -113,7 +113,7 @@ Q_GLOBAL_STATIC(QSystemLocaleData, qSystemLocaleData)
#ifndef QT_NO_SYSTEMLOCALE
static bool contradicts(const QString &maybe, const QString &known)
static bool contradicts(QStringView maybe, const QString &known)
{
if (maybe.isEmpty())
return false;
@ -149,11 +149,10 @@ QLocale QSystemLocale::fallbackLocale() const
// ... otherwise, if the first part of LANGUAGE says more than or
// contradicts what we have, use that:
QString language = qEnvironmentVariable("LANGUAGE");
if (!language.isEmpty()) {
language = language.split(QLatin1Char(':')).constFirst();
for (const auto &language : qEnvironmentVariable("LANGUAGE").tokenize(QLatin1Char(':'))) {
if (contradicts(language, lang))
return QLocale(language);
break; // We only look at the first entry.
}
return QLocale(lang);