From 5ec57560c0b497f9f48671dd200bb23d1f6eac35 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 29 Mar 2017 07:10:46 +0300 Subject: Prefer rvalue versions of toLatin() and toUtf8() ... to re-use existing buffers. Change-Id: I7c42529b8cd4400520a59e658ab76f4f8e965cd4 Reviewed-by: Thiago Macieira --- src/corelib/io/qsettings_mac.cpp | 2 +- src/corelib/io/qurl.cpp | 6 ++---- src/corelib/tools/qlocale_win.cpp | 13 +++++-------- src/corelib/tools/qregularexpression.cpp | 2 +- src/corelib/tools/qtimezoneprivate_icu.cpp | 2 +- src/corelib/tools/qtimezoneprivate_win.cpp | 2 +- src/network/access/qhttpnetworkconnection.cpp | 2 +- src/network/access/qhttpthreaddelegate.cpp | 2 +- src/plugins/platforms/windows/qwindowsmime.cpp | 2 +- src/plugins/platforms/xcb/qxcbmime.cpp | 2 +- src/plugins/platforms/xcb/qxcbwindow.cpp | 4 ++-- src/testlib/qplaintestlogger.cpp | 2 +- src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 4 ++-- src/widgets/widgets/qsplitter.cpp | 2 +- src/xml/dom/qdom.cpp | 2 +- src/xml/sax/qxml.cpp | 2 +- 16 files changed, 23 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index cf3a480623..2a08ee2e64 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -211,7 +211,7 @@ static QCFType macValue(const QVariant &value) default: QString string = QSettingsPrivate::variantToString(value); if (string.contains(QChar::Null)) - result = string.toUtf8().toCFData(); + result = std::move(string).toUtf8().toCFData(); else result = string.toCFString(); } diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index b5772b5ce2..9663235a67 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3418,8 +3418,7 @@ QUrl QUrl::adjusted(QUrl::FormattingOptions options) const QByteArray QUrl::toEncoded(FormattingOptions options) const { options &= ~(FullyDecoded | FullyEncoded); - QString stringForm = toString(options | FullyEncoded); - return stringForm.toLatin1(); + return toString(options | FullyEncoded).toLatin1(); } /*! @@ -3536,8 +3535,7 @@ QString QUrl::fromAce(const QByteArray &domain) */ QByteArray QUrl::toAce(const QString &domain) { - QString result = qt_ACE_do(domain, ToAceOnly, ForbidLeadingDot /*FIXME: make configurable*/); - return result.toLatin1(); + return qt_ACE_do(domain, ToAceOnly, ForbidLeadingDot /*FIXME: make configurable*/).toLatin1(); } /*! diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp index d1abb8b565..2475859abd 100644 --- a/src/corelib/tools/qlocale_win.cpp +++ b/src/corelib/tools/qlocale_win.cpp @@ -1037,7 +1037,7 @@ static QString winIso639LangName(LPWSTR id) if (!lang_code.isEmpty()) { const char *endptr; bool ok; - QByteArray latin1_lang_code = lang_code.toLatin1(); + QByteArray latin1_lang_code = std::move(lang_code).toLatin1(); int i = qstrtoull(latin1_lang_code, &endptr, 16, &ok); if (ok && *endptr == '\0') { switch (i) { @@ -1120,15 +1120,12 @@ static QByteArray getWinLocaleName(LPWSTR id) id = lcName; } #endif // Q_OS_WINRT - QString resultuage = winIso639LangName(id); + QString resultusage = winIso639LangName(id); QString country = winIso3116CtryName(id); - result = resultuage.toLatin1(); - if (!country.isEmpty()) { - result += '_'; - result += country.toLatin1(); - } + if (!country.isEmpty()) + resultusage += QLatin1Char('_') + country; - return result; + return std::move(resultusage).toLatin1(); } Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id) diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 8366e01ee8..f1fac093b0 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1674,7 +1674,7 @@ QString QRegularExpression::errorString() const } while (errorStringLength < 0); errorString.resize(errorStringLength); - return QCoreApplication::translate("QRegularExpression", errorString.toLatin1().constData()); + return QCoreApplication::translate("QRegularExpression", std::move(errorString).toLatin1().constData()); } return QCoreApplication::translate("QRegularExpression", "no error"); } diff --git a/src/corelib/tools/qtimezoneprivate_icu.cpp b/src/corelib/tools/qtimezoneprivate_icu.cpp index 887486f567..a7226f2720 100644 --- a/src/corelib/tools/qtimezoneprivate_icu.cpp +++ b/src/corelib/tools/qtimezoneprivate_icu.cpp @@ -98,7 +98,7 @@ static QByteArray ucalDefaultTimeZoneId() // If successful on first or second go, resize and return if (U_SUCCESS(status)) { result.resize(size); - return result.toUtf8(); + return std::move(result).toUtf8(); } return QByteArray(); diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp index 16dfaefb74..f963e10333 100644 --- a/src/corelib/tools/qtimezoneprivate_win.cpp +++ b/src/corelib/tools/qtimezoneprivate_win.cpp @@ -299,7 +299,7 @@ static QByteArray windowsSystemZoneId() id = readRegistryString(key, L"TimeZoneKeyName"); RegCloseKey(key); if (!id.isEmpty()) - return id.toUtf8(); + return std::move(id).toUtf8(); } // On XP we have to iterate over the zones until we find a match on diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 72feffda8c..da055de2da 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -327,7 +327,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) acceptLanguage = systemLocale + QLatin1String(",*"); else acceptLanguage = systemLocale + QLatin1String(",en,*"); - request.setHeaderField("Accept-Language", acceptLanguage.toLatin1()); + request.setHeaderField("Accept-Language", std::move(acceptLanguage).toLatin1()); } // set the User Agent diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 6e5e29d7bf..9d874b4d94 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -169,7 +169,7 @@ static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy) Q_UNUSED(proxy) #endif - return "http-connection:" + result.toLatin1(); + return "http-connection:" + std::move(result).toLatin1(); } class QNetworkAccessCachedHttpConnection: public QHttpNetworkConnection, diff --git a/src/plugins/platforms/windows/qwindowsmime.cpp b/src/plugins/platforms/windows/qwindowsmime.cpp index 71fd12d71b..bd4822c664 100644 --- a/src/plugins/platforms/windows/qwindowsmime.cpp +++ b/src/plugins/platforms/windows/qwindowsmime.cpp @@ -717,7 +717,7 @@ QVariant QWindowsMimeText::convertToMime(const QString &mime, LPDATAOBJECT pData if (preferredType == QVariant::String) ret = str; else - ret = str.toUtf8(); + ret = std::move(str).toUtf8(); } qCDebug(lcQpaMime) << __FUNCTION__ << ret; return ret; diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 7592eb2887..186f31e08a 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -305,7 +305,7 @@ xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString QString formatWithCharset = format; formatWithCharset.append(QLatin1String(";charset=utf-8")); - xcb_atom_t a = connection->internAtom(formatWithCharset.toLatin1()); + xcb_atom_t a = connection->internAtom(std::move(formatWithCharset).toLatin1()); if (a && atoms.contains(a)) { *requestedEncoding = "utf-8"; return a; diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index f6fa903ec2..77291cc4f5 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -1512,8 +1512,8 @@ void QXcbWindow::setParent(const QPlatformWindow *parent) void QXcbWindow::setWindowTitle(const QString &title) { - const QString fullTitle = formatWindowTitle(title, QString::fromUtf8(" \xe2\x80\x94 ")); // unicode character U+2014, EM DASH - const QByteArray ba = fullTitle.toUtf8(); + QString fullTitle = formatWindowTitle(title, QString::fromUtf8(" \xe2\x80\x94 ")); // unicode character U+2014, EM DASH + const QByteArray ba = std::move(fullTitle).toUtf8(); Q_XCB_CALL(xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index dc20d922e5..77959341cf 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -199,8 +199,8 @@ namespace QTest { int formatResult(char * buffer, int bufferSize, T number, int significantDigits) { QString result = formatResult(number, significantDigits); - qstrncpy(buffer, result.toLatin1().constData(), bufferSize); int size = result.count(); + qstrncpy(buffer, std::move(result).toLatin1().constData(), bufferSize); return size; } } diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp index cdf3ad3310..9ccf8be73a 100644 --- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp +++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp @@ -217,7 +217,7 @@ static QByteArray qtTypeName(const QString &signature, const QDBusIntrospection: annotationName += QString::fromLatin1(".%1%2").arg(QLatin1String(direction)).arg(paramId); QString qttype = annotations.value(annotationName); if (!qttype.isEmpty()) - return qttype.toLatin1(); + return std::move(qttype).toLatin1(); QString oldAnnotationName = QString::fromLatin1("com.trolltech.QtDBus.QtTypeName"); if (paramId >= 0) @@ -242,7 +242,7 @@ static QByteArray qtTypeName(const QString &signature, const QDBusIntrospection: "suggest updating to '%s'\n", PROGRAMNAME, qPrintable(oldAnnotationName), qPrintable(inputFile), qPrintable(annotationName)); - return qttype.toLatin1(); + return std::move(qttype).toLatin1(); } return QVariant::typeToName(QVariant::Type(type)); diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index c55b943b5a..e92347c65c 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1800,7 +1800,7 @@ QTextStream& operator>>(QTextStream& ts, QSplitter& splitter) line.replace(QLatin1Char(' '), QString()); line = std::move(line).toUpper(); - splitter.restoreState(line.toLatin1()); + splitter.restoreState(std::move(line).toLatin1()); return ts; } diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index dd9bb4f875..9affd697a0 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -6442,7 +6442,7 @@ void QDomDocumentPrivate::saveDocument(QTextStream& s, const int indent, QDomNod if (enc.isEmpty()) enc = encoding.cap(5); if (!enc.isEmpty()) - codec = QTextCodec::codecForName(enc.toLatin1().data()); + codec = QTextCodec::codecForName(std::move(enc).toLatin1()); } if (!codec) codec = QTextCodec::codecForName("UTF-8"); diff --git a/src/xml/sax/qxml.cpp b/src/xml/sax/qxml.cpp index 1724076b84..bc7d00483a 100644 --- a/src/xml/sax/qxml.cpp +++ b/src/xml/sax/qxml.cpp @@ -1407,7 +1407,7 @@ QString QXmlInputSource::fromRawData(const QByteArray &data, bool beginning) QString encoding = extractEncodingDecl(d->encodingDeclChars, &needMoreText); if (!encoding.isEmpty()) { - if (QTextCodec *codec = QTextCodec::codecForName(encoding.toLatin1())) { + if (QTextCodec *codec = QTextCodec::codecForName(std::move(encoding).toLatin1())) { /* If the encoding is the same, we don't have to do toUnicode() all over again. */ if(codec->mibEnum() != mib) { delete d->encMapper; -- cgit v1.2.3