QtCore: use QStringRef in more places

Apart from removing some unwanted allocations, also reduces
text size by ~800B on Linux AMD64 GCC 4.9 release builds.

Change-Id: Ibcd1d8264f54f2b165b69bee8aa50ff7f4ad3a10
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-10-10 23:40:58 +02:00
parent 2a1ea8f13b
commit 690f9a7e74
7 changed files with 16 additions and 15 deletions

View File

@ -152,7 +152,7 @@ static bool _q_resolveEntryAndCreateLegacyEngine_recursive(QFileSystemEntry &ent
const QStringList &paths = QDir::searchPaths(filePath.left(prefixSeparator));
for (int i = 0; i < paths.count(); i++) {
entry = QFileSystemEntry(QDir::cleanPath(paths.at(i) % QLatin1Char('/') % filePath.mid(prefixSeparator + 1)));
entry = QFileSystemEntry(QDir::cleanPath(paths.at(i) % QLatin1Char('/') % filePath.midRef(prefixSeparator + 1)));
// Recurse!
if (_q_resolveEntryAndCreateLegacyEngine_recursive(entry, data, engine, true))
return true;

View File

@ -53,8 +53,7 @@ static bool isUncRoot(const QString &server)
if (idx == -1 || idx + 1 == localPath.length())
return true;
localPath = localPath.right(localPath.length() - idx - 1).trimmed();
return localPath.isEmpty();
return localPath.rightRef(localPath.length() - idx - 1).trimmed().isEmpty();
}
static inline QString fixIfRelativeUncPath(const QString &path)

View File

@ -296,7 +296,9 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths)
QFileSystemWatcherEngine *engine = 0;
if(!objectName().startsWith(QLatin1String("_qt_autotest_force_engine_"))) {
const QString on = objectName();
if (!on.startsWith(QLatin1String("_qt_autotest_force_engine_"))) {
// Normal runtime case - search intelligently for best engine
if(d->native) {
engine = d->native;
@ -307,7 +309,7 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths)
} else {
// Autotest override case - use the explicitly selected engine only
QString forceName = objectName().mid(26);
const QStringRef forceName = on.midRef(26);
if(forceName == QLatin1String("poller")) {
qDebug() << "QFileSystemWatcher: skipping native engine, using only polling engine";
d_func()->initPollerEngine();

View File

@ -800,8 +800,8 @@ bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const
{
const QString root = mappingRoot();
if(!root.isEmpty()) {
const QStringList root_segments = root.split(QLatin1Char('/'), QString::SkipEmptyParts),
path_segments = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
const QVector<QStringRef> root_segments = root.splitRef(QLatin1Char('/'), QString::SkipEmptyParts),
path_segments = path.splitRef(QLatin1Char('/'), QString::SkipEmptyParts);
if(path_segments.size() <= root_segments.size()) {
int matched = 0;
for(int i = 0; i < path_segments.size(); ++i) {
@ -811,7 +811,7 @@ bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const
}
if(matched == path_segments.size()) {
if(match && root_segments.size() > matched)
*match = root_segments.at(matched);
*match = root_segments.at(matched).toString();
return true;
}
}

View File

@ -488,7 +488,7 @@ QVariant QSettingsPrivate::stringToVariant(const QString &s)
if (s.startsWith(QLatin1Char('@'))) {
if (s.endsWith(QLatin1Char(')'))) {
if (s.startsWith(QLatin1String("@ByteArray("))) {
return QVariant(s.toLatin1().mid(11, s.size() - 12));
return QVariant(s.midRef(11, s.size() - 12).toLatin1());
} else if (s.startsWith(QLatin1String("@Variant("))
|| s.startsWith(QLatin1String("@DateTime("))) {
#ifndef QT_NO_DATASTREAM
@ -501,7 +501,7 @@ QVariant QSettingsPrivate::stringToVariant(const QString &s)
version = QDataStream::Qt_4_0;
offset = 9;
}
QByteArray a(s.toLatin1().mid(offset));
QByteArray a = s.midRef(offset).toLatin1();
QDataStream stream(&a, QIODevice::ReadOnly);
stream.setVersion(version);
QVariant result;

View File

@ -403,11 +403,11 @@ QMacSettingsPrivate::QMacSettingsPrivate(QSettings::Scope scope, const QString &
}
while ((nextDot = domainName.indexOf(QLatin1Char('.'), curPos)) != -1) {
javaPackageName.prepend(domainName.mid(curPos, nextDot - curPos));
javaPackageName.prepend(domainName.midRef(curPos, nextDot - curPos));
javaPackageName.prepend(QLatin1Char('.'));
curPos = nextDot + 1;
}
javaPackageName.prepend(domainName.mid(curPos));
javaPackageName.prepend(domainName.midRef(curPos));
javaPackageName = javaPackageName.toLower();
if (curPos == 0)
javaPackageName.prepend(QLatin1String("com."));

View File

@ -286,9 +286,9 @@ static QString locatePlugin(const QString& fileName)
suffixes.prepend(QString());
// Split up "subdir/filename"
const int slash = fileName.lastIndexOf('/');
const QString baseName = fileName.mid(slash + 1);
const QString basePath = isAbsolute ? QString() : fileName.left(slash + 1); // keep the '/'
const int slash = fileName.lastIndexOf(QLatin1Char('/'));
const QStringRef baseName = fileName.midRef(slash + 1);
const QStringRef basePath = isAbsolute ? QStringRef() : fileName.leftRef(slash + 1); // keep the '/'
const bool debug = qt_debug_component();