From a3e563c0913e5bc1607ea7f60187591ec7eabe50 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 15 Aug 2012 18:15:06 +0200 Subject: 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 Reviewed-by: Lars Knoll --- src/corelib/tools/qstring.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/corelib') 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(); } -- cgit v1.2.3