summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-01-24 11:10:19 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-01-26 07:34:06 +0000
commit6ca81d1fd17df525fb51033fbdad6c99b332f234 (patch)
tree42078dfb0b4417dc973e98da9e03398b0a97618d /src/corelib/kernel
parent037e58fff634ab8f04cf834446517a4265279039 (diff)
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 <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qtranslator.cpp7
1 files changed, 5 insertions, 2 deletions
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