summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-08-31 17:17:33 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-09-07 21:09:49 +0200
commit0108275b0c6a38ac73014c8e135b9be9fe75c8b2 (patch)
tree170ba0918e4c765a1bb001d9b9e0bff424e66216 /src/corelib/text
parent121fddcf5ae2ab238ef802e44b45ce62c56015f5 (diff)
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>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qlocale_unix.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp
index 346d624f7b..4eaefe0e72 100644
--- a/src/corelib/text/qlocale_unix.cpp
+++ b/src/corelib/text/qlocale_unix.cpp
@@ -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);