From 0108275b0c6a38ac73014c8e135b9be9fe75c8b2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 31 Aug 2021 17:17:33 +0200 Subject: Unix fallbackLocale(): use QString::tokenize() rather than split() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- src/corelib/text/qlocale_unix.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/corelib/text') 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); -- cgit v1.2.3