Prefer rvalue versions of toLatin() and toUtf8()

... to re-use existing buffers.

Change-Id: I7c42529b8cd4400520a59e658ab76f4f8e965cd4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Anton Kudryavtsev 2017-03-29 07:10:46 +03:00
parent ce124d5119
commit 5ec57560c0
16 changed files with 23 additions and 28 deletions

View File

@ -211,7 +211,7 @@ static QCFType<CFPropertyListRef> 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();
}

View File

@ -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();
}
/*!

View File

@ -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)

View File

@ -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");
}

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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;
}
}

View File

@ -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));

View File

@ -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;
}

View File

@ -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");

View File

@ -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;