From 5dc739ba9b09326bf113bb7f4ce9aa45fe671c6b Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 5 Jul 2016 16:25:40 +0300 Subject: Replace QString::trimmed() with QStringRef::trimmed() ... where it's possible. Reduce allocations. Change-Id: I023adfd316f94948fe50749f60bf55748dca56e2 Reviewed-by: Edward Welbourne --- src/gui/text/qtexthtmlparser.cpp | 8 ++++---- src/network/access/qftp.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 103a208c26..50df8daa5e 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1418,16 +1418,16 @@ static bool setFloatAttribute(qreal *destination, const QString &value) return ok; } -static void setWidthAttribute(QTextLength *width, QString value) +static void setWidthAttribute(QTextLength *width, const QString &valueStr) { bool ok = false; - qreal realVal = value.toDouble(&ok); + qreal realVal = valueStr.toDouble(&ok); if (ok) { *width = QTextLength(QTextLength::FixedLength, realVal); } else { - value = value.trimmed(); + QStringRef value = QStringRef(&valueStr).trimmed(); if (!value.isEmpty() && value.endsWith(QLatin1Char('%'))) { - value.chop(1); + value.truncate(value.size() - 1); realVal = value.toDouble(&ok); if (ok) *width = QTextLength(QTextLength::PercentageLength, realVal); diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 19b519243c..7b6f830333 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -2034,7 +2034,7 @@ int QFtp::rename(const QString &oldname, const QString &newname) */ int QFtp::rawCommand(const QString &command) { - QString cmd = command.trimmed() + QLatin1String("\r\n"); + const QString cmd = QStringRef(&command).trimmed() + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(RawCommand, QStringList(cmd))); } @@ -2253,8 +2253,8 @@ void QFtpPrivate::_q_startNextCommand() // Proxy support, replace the Login argument in place, then fall // through. if (c->command == QFtp::Login && !proxyHost.isEmpty()) { - QString loginString = c->rawCmds.constFirst().trimmed(); - loginString += QLatin1Char('@') + host; + QString loginString; + loginString += QStringRef(&c->rawCmds.constFirst()).trimmed() + QLatin1Char('@') + host; if (port && port != 21) loginString += QLatin1Char(':') + QString::number(port); loginString += QLatin1String("\r\n"); -- cgit v1.2.3