From 6ca81d1fd17df525fb51033fbdad6c99b332f234 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Sun, 24 Jan 2016 11:10:19 +0300 Subject: QTranslator: don't re-create QString each time through a loop Just cache it. Also port to QStringLiteral, because the string is never modified. Since the string literal is used in more than one function, to avoid duplication of .rodata, wrap the QStringLiteral in an inline function. Change-Id: Ib5aede9f129610c80d122939afc343c938cc8e48 Reviewed-by: Marc Mutz --- src/corelib/kernel/qtranslator.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index b88578dd89..bbfccf3f3a 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -91,6 +91,8 @@ static const uchar magic[MagicLength] = { 0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd }; +static inline QString dotQmLiteral() { return QStringLiteral(".qm"); } + static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen) { // catch the case if \a found has a zero-terminating symbol and \a len includes it. @@ -484,6 +486,7 @@ bool QTranslator::load(const QString & filename, const QString & directory, prefix += QLatin1Char('/'); } + const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix; QString fname = filename; QString realname; QString delims; @@ -492,7 +495,7 @@ bool QTranslator::load(const QString & filename, const QString & directory, for (;;) { QFileInfo fi; - realname = prefix + fname + (suffix.isNull() ? QString::fromLatin1(".qm") : suffix); + realname = prefix + fname + suffixOrDotQM; fi.setFile(realname); if (fi.isReadable() && fi.isFile()) break; @@ -638,7 +641,7 @@ static QString find_translation(const QLocale & locale, if (!path.isEmpty() && !path.endsWith(QLatin1Char('/'))) path += QLatin1Char('/'); } - const QString suffixOrDotQM = suffix.isNull() ? QStringLiteral(".qm") : suffix; + const QString suffixOrDotQM = suffix.isNull() ? dotQmLiteral() : suffix; QString realname; realname += path + filename + prefix; // using += in the hope for some reserve capacity -- cgit v1.2.3