From 8617ce5c881c7913e144153494b15d60ca0c0e83 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 11 Jul 2016 16:08:00 +0300 Subject: Use QStringRef() more, exploiting its new ::chop() Change-Id: Id2201639be604b9a32b2dc5d21e675a961bee477 Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/corelib/io/qurl.cpp | 22 +++++++++++++++------- src/gui/painting/qpagesize.cpp | 2 +- src/gui/text/qcssparser.cpp | 20 ++++++++++++-------- src/gui/text/qzip.cpp | 10 ++++++---- 4 files changed, 34 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 9cf1be58d8..42a742213b 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -833,7 +833,7 @@ recodeFromUser(const QString &input, const ushort *actions, int from, int to) // appendXXXX functions: copy from the internal form to the external, user form. // the internal value is stored in its PrettyDecoded form, so that case is easy. -static inline void appendToUser(QString &appendTo, const QString &value, QUrl::FormattingOptions options, +static inline void appendToUser(QString &appendTo, const QStringRef &value, QUrl::FormattingOptions options, const ushort *actions) { if (options == QUrl::PrettyDecoded) { @@ -841,10 +841,17 @@ static inline void appendToUser(QString &appendTo, const QString &value, QUrl::F return; } - if (!qt_urlRecode(appendTo, value.constData(), value.constEnd(), options, actions)) + if (!qt_urlRecode(appendTo, value.data(), value.end(), options, actions)) appendTo += value; } +static inline void appendToUser(QString &appendTo, const QString &value, QUrl::FormattingOptions options, + const ushort *actions) +{ + appendToUser(appendTo, QStringRef(&value), options, actions); +} + + inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const { if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) { @@ -924,21 +931,22 @@ inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions o if (options & QUrl::NormalizePathSegments) { thePath = qt_normalizePathSegments(path, false); } + + QStringRef thePathRef(&thePath); if (options & QUrl::RemoveFilename) { const int slash = path.lastIndexOf(QLatin1Char('/')); if (slash == -1) return; - thePath = path.left(slash+1); + thePathRef = path.leftRef(slash + 1); } // check if we need to remove trailing slashes if (options & QUrl::StripTrailingSlash) { - while (thePath.length() > 1 && thePath.endsWith(QLatin1Char('/'))) - thePath.chop(1); + while (thePathRef.length() > 1 && thePathRef.endsWith(QLatin1Char('/'))) + thePathRef.chop(1); } - appendToUser(appendTo, thePath, options, + appendToUser(appendTo, thePathRef, options, appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? pathInUrl : pathInIsolation); - } inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const diff --git a/src/gui/painting/qpagesize.cpp b/src/gui/painting/qpagesize.cpp index f53285d9cb..8831d60d48 100644 --- a/src/gui/painting/qpagesize.cpp +++ b/src/gui/painting/qpagesize.cpp @@ -400,7 +400,7 @@ static QPageSize::PageSizeId qt_idForPpdKey(const QString &ppdKey, QSize *match { if (ppdKey.isEmpty()) return QPageSize::Custom; - QString key = ppdKey; + QStringRef key(&ppdKey); // Remove any Rotated or Tranverse modifiers if (key.endsWith(QLatin1String("Rotated"))) key.chop(7); diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 72c5d5ff33..8894e4884b 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -403,8 +403,8 @@ ValueExtractor::ValueExtractor(const QVector &decls, const QPalette LengthData ValueExtractor::lengthValue(const Value& v) { - QString s = v.variant.toString(); - s.reserve(s.length()); + const QString str = v.variant.toString(); + QStringRef s(&str); LengthData data; data.unit = LengthData::None; if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) @@ -1442,11 +1442,13 @@ bool Declaration::realValue(qreal *real, const char *unit) const const Value &v = d->values.at(0); if (unit && v.type != Value::Length) return false; - QString s = v.variant.toString(); + const QString str = v.variant.toString(); + QStringRef s(&str); if (unit) { - if (!s.endsWith(QLatin1String(unit), Qt::CaseInsensitive)) + const QLatin1String unitStr(unit); + if (!s.endsWith(unitStr, Qt::CaseInsensitive)) return false; - s.chop(qstrlen(unit)); + s.chop(unitStr.size()); } bool ok = false; qreal val = s.toDouble(&ok); @@ -1459,11 +1461,13 @@ static bool intValueHelper(const QCss::Value &v, int *i, const char *unit) { if (unit && v.type != Value::Length) return false; - QString s = v.variant.toString(); + const QString str = v.variant.toString(); + QStringRef s(&str); if (unit) { - if (!s.endsWith(QLatin1String(unit), Qt::CaseInsensitive)) + const QLatin1String unitStr(unit); + if (!s.endsWith(unitStr, Qt::CaseInsensitive)) return false; - s.chop(qstrlen(unit)); + s.chop(unitStr.size()); } bool ok = false; int val = s.toInt(&ok); diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp index 7cb89543ba..b68c36fd9e 100644 --- a/src/gui/text/qzip.cpp +++ b/src/gui/text/qzip.cpp @@ -498,11 +498,13 @@ QZipReader::FileInfo QZipPrivate::fillFileInfo(int index) const // fix the file path, if broken (convert separators, eat leading and trailing ones) fileInfo.filePath = QDir::fromNativeSeparators(fileInfo.filePath); - while (!fileInfo.filePath.isEmpty() && (fileInfo.filePath.at(0) == QLatin1Char('.') || fileInfo.filePath.at(0) == QLatin1Char('/'))) - fileInfo.filePath = fileInfo.filePath.mid(1); - while (!fileInfo.filePath.isEmpty() && fileInfo.filePath.at(fileInfo.filePath.size() - 1) == QLatin1Char('/')) - fileInfo.filePath.chop(1); + QStringRef filePathRef(&fileInfo.filePath); + while (filePathRef.startsWith(QLatin1Char('.')) || filePathRef.startsWith(QLatin1Char('/'))) + filePathRef = filePathRef.mid(1); + while (filePathRef.endsWith(QLatin1Char('/'))) + filePathRef.chop(1); + fileInfo.filePath = filePathRef.toString(); return fileInfo; } -- cgit v1.2.3