summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-15 18:15:06 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-23 00:19:25 +0200
commita3e563c0913e5bc1607ea7f60187591ec7eabe50 (patch)
treebafef25438b1e6707e6bca861f9dc130f22f18e9 /src/corelib/tools
parent12491f35bbea7008b15fb0ba0ee7ea5bf6eb6b6c (diff)
Simple optimisation in toLocal8Bit(): call codecForLocale once only
The function is only slow the first time we call it, but there's no reason we can't do this simple optimisation anyway. Change-Id: Icacbbeb340838b32f5278b76d1860ad22dc9f7b7 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index ff5e24dd85..6b47d6a55a 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -3931,8 +3931,9 @@ QByteArray QString::toLatin1() const
static QByteArray toLocal8Bit_helper(const QChar *data, int length)
{
#ifndef QT_NO_TEXTCODEC
- if (QTextCodec::codecForLocale())
- return QTextCodec::codecForLocale()->fromUnicode(data, length);
+ QTextCodec *localeCodec = QTextCodec::codecForLocale();
+ if (localeCodec)
+ return localeCodec->fromUnicode(data, length);
#endif // QT_NO_TEXTCODEC
return toLatin1_helper(data, length);
}
@@ -3956,8 +3957,9 @@ static QByteArray toLocal8Bit_helper(const QChar *data, int length)
QByteArray QString::toLocal8Bit() const
{
#ifndef QT_NO_TEXTCODEC
- if (QTextCodec::codecForLocale())
- return QTextCodec::codecForLocale()->fromUnicode(*this);
+ QTextCodec *localeCodec = QTextCodec::codecForLocale();
+ if (localeCodec)
+ return localeCodec->fromUnicode(*this);
#endif // QT_NO_TEXTCODEC
return toLatin1();
}
@@ -9080,8 +9082,9 @@ QByteArray QStringRef::toLatin1() const
QByteArray QStringRef::toLocal8Bit() const
{
#ifndef QT_NO_TEXTCODEC
- if (QTextCodec::codecForLocale())
- return QTextCodec::codecForLocale()->fromUnicode(unicode(), length());
+ QTextCodec *localeCodec = QTextCodec::codecForLocale();
+ if (localeCodec)
+ return localeCodec->fromUnicode(unicode(), length());
#endif // QT_NO_TEXTCODEC
return toLatin1();
}