From 5034d4163048c74668ab0f33e963b9eab3d206a0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 27 Dec 2015 11:05:43 +0100 Subject: [PATCH] QTranslator: don't repeatedly re-create a QString from a QLatin1String ... each time around the loops. Cache it. Also use QStringLiteral, since the string will never be modified. Also saves 96b in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I0269586235da18f3073a553739561ea7db6356e8 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qtranslator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 6df1380d8d..dad471c1b0 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -632,6 +632,7 @@ static QString find_translation(const QLocale & locale, if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) path += QLatin1Char('/'); } + const QString suffixOrDotQM = suffix.isNull() ? QStringLiteral(".qm") : suffix; QString realname; realname += path + filename + prefix; // using += in the hope for some reserve capacity @@ -654,7 +655,7 @@ static QString find_translation(const QLocale & locale, foreach (QString localeName, languages) { localeName.replace(QLatin1Char('-'), QLatin1Char('_')); - realname += localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix); + realname += localeName + suffixOrDotQM; if (is_readable_file(realname)) return realname; @@ -675,7 +676,7 @@ static QString find_translation(const QLocale & locale, break; localeName.truncate(rightmost); - realname += localeName + (suffix.isNull() ? QLatin1String(".qm") : suffix); + realname += localeName + suffixOrDotQM; if (is_readable_file(realname)) return realname;