Use QStringRef() more, exploiting its new ::chop()

Change-Id: Id2201639be604b9a32b2dc5d21e675a961bee477
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Anton Kudryavtsev 2016-07-11 16:08:00 +03:00
parent ff00b2efbd
commit 8617ce5c88
4 changed files with 34 additions and 20 deletions

View File

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

View File

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

View File

@ -403,8 +403,8 @@ ValueExtractor::ValueExtractor(const QVector<Declaration> &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);

View File

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