aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-04-06 15:23:58 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-04-26 10:31:19 +0000
commit1be53f4e143d417d60cd1f9a292193dab59b5b20 (patch)
treeefc9f54af4d646d9e7d5618e3c2688d9442bbc71 /src
parent84f61dd2d2b0140814b39a2c5238a6e31c49abd7 (diff)
Use QStringRef to optimize memory allocation
Replace substring functions that return QString with corresponding functions that return QStringRef where it's possible. Create QString from QStringRef only where necessary. While touching the code, also port loops to C++11 style. Change-Id: I04c99b24ea6afd3715e3edf9ea00bfab838fd53c Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com> Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com> Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp12
-rw-r--r--src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp2
-rw-r--r--src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp14
-rw-r--r--src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp41
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp8
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp14
-rw-r--r--src/qml/compiler/qqmltypecompiler_p.h6
-rw-r--r--src/qml/compiler/qv4compileddata.cpp4
-rw-r--r--src/qml/qml/qqmlerror.cpp7
-rw-r--r--src/qml/qml/qqmlfile.cpp2
-rw-r--r--src/qml/qml/qqmlimport.cpp15
-rw-r--r--src/qml/qml/qqmlproperty.cpp16
-rw-r--r--src/qml/types/qqmldelegatemodel.cpp2
-rw-r--r--src/qmltest/quicktest.cpp2
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp28
-rw-r--r--src/quick/items/qquickpathview.cpp2
-rw-r--r--src/quick/items/qquickscalegrid.cpp45
-rw-r--r--src/quick/items/qquickscalegrid_p_p.h2
-rw-r--r--src/quick/items/qquicktextinput.cpp2
-rw-r--r--src/quick/scenegraph/util/qsgshadersourcebuilder.cpp6
-rw-r--r--src/quick/util/qquickanimation.cpp2
-rw-r--r--src/quick/util/qquickglobal.cpp22
-rw-r--r--src/quick/util/qquickstategroup.cpp18
23 files changed, 141 insertions, 131 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp
index a9996da7f4..ff4e30835d 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qqmlenginedebugservice.cpp
@@ -683,11 +683,13 @@ bool QQmlEngineDebugServiceImpl::resetBinding(int objectId, const QString &prope
QQmlContext *context = qmlContext(object);
if (object && context) {
- QString parentProperty = propertyName;
- if (propertyName.indexOf(QLatin1Char('.')) != -1)
- parentProperty = propertyName.left(propertyName.indexOf(QLatin1Char('.')));
+ QStringRef parentPropertyRef(&propertyName);
+ const int idx = parentPropertyRef.indexOf(QLatin1Char('.'));
+ if (idx != -1)
+ parentPropertyRef = parentPropertyRef.left(idx);
- if (object->property(parentProperty.toLatin1()).isValid()) {
+ const QByteArray parentProperty = parentPropertyRef.toLatin1();
+ if (object->property(parentProperty).isValid()) {
QQmlProperty property(object, propertyName);
QQmlPropertyPrivate::removeBinding(property);
if (property.isResettable()) {
@@ -700,7 +702,7 @@ bool QQmlEngineDebugServiceImpl::resetBinding(int objectId, const QString &prope
// overwrite with default value
if (QQmlType *objType = QQmlMetaType::qmlType(object->metaObject())) {
if (QObject *emptyObject = objType->create()) {
- if (emptyObject->property(parentProperty.toLatin1()).isValid()) {
+ if (emptyObject->property(parentProperty).isValid()) {
QVariant defaultValue = QQmlProperty(emptyObject, propertyName).read();
if (defaultValue.isValid()) {
setBinding(objectId, propertyName, defaultValue, true);
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp b/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp
index 877821e03f..a9b9587aa9 100644
--- a/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp
+++ b/src/plugins/qmltooling/qmldbg_debugger/qqmlnativedebugservice.cpp
@@ -704,7 +704,7 @@ bool NativeDebugger::reallyHitTheBreakPoint(const QV4::Function *function, int l
const BreakPoint &bp = m_service->m_breakHandler->m_breakPoints.at(i);
if (bp.lineNumber == lineNumber) {
const QString fileName = function->sourceFile();
- const QString base = fileName.mid(fileName.lastIndexOf('/') + 1);
+ const QStringRef base = fileName.midRef(fileName.lastIndexOf('/') + 1);
if (bp.fileName.endsWith(base)) {
if (bp.condition.isEmpty() || checkCondition(bp.condition)) {
BreakPoint &mbp = m_service->m_breakHandler->m_breakPoints[i];
diff --git a/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp b/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp
index cc0118f0c2..3145601612 100644
--- a/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp
+++ b/src/plugins/qmltooling/qmldbg_native/qqmlnativedebugconnector.cpp
@@ -49,6 +49,7 @@
#include <QtCore/qjsonobject.h>
#include <QtCore/qjsonvalue.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qvector.h>
//#define TRACE_PROTOCOL(s) qDebug() << s
#define TRACE_PROTOCOL(s)
@@ -182,24 +183,21 @@ QQmlNativeDebugConnector::QQmlNativeDebugConnector()
: m_blockingMode(false)
{
const QString args = commandLineArguments();
- const QStringList lstjsDebugArguments = args.split(QLatin1Char(','));
+ const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','));
QStringList services;
- QStringList::const_iterator argsItEnd = lstjsDebugArguments.cend();
- QStringList::const_iterator argsIt = lstjsDebugArguments.cbegin();
- for (; argsIt != argsItEnd; ++argsIt) {
- const QString strArgument = *argsIt;
+ for (const QStringRef &strArgument : lstjsDebugArguments) {
if (strArgument == QLatin1String("block")) {
m_blockingMode = true;
} else if (strArgument == QLatin1String("native")) {
// Ignore. This is used to signal that this connector
// should be loaded and that has already happened.
} else if (strArgument.startsWith(QLatin1String("services:"))) {
- services.append(strArgument.mid(9));
+ services.append(strArgument.mid(9).toString());
} else if (!services.isEmpty()) {
- services.append(strArgument);
+ services.append(strArgument.toString());
} else {
qWarning("QML Debugger: Invalid argument \"%s\" detected. Ignoring the same.",
- qUtf8Printable(strArgument));
+ strArgument.toUtf8().constData());
}
}
setServices(services);
diff --git a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
index 28213e7b56..a6d93e85ae 100644
--- a/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
+++ b/src/plugins/qmltooling/qmldbg_server/qqmldebugserver.cpp
@@ -53,6 +53,7 @@
#include <QtCore/QDir>
#include <QtCore/QPluginLoader>
#include <QtCore/QStringList>
+#include <QtCore/QVector>
#include <QtCore/qwaitcondition.h>
QT_BEGIN_NAMESPACE
@@ -345,40 +346,40 @@ void QQmlDebugServerImpl::parseArguments()
QString fileName;
QStringList services;
- const QStringList lstjsDebugArguments = args.split(QLatin1Char(','));
- QStringList::const_iterator argsItEnd = lstjsDebugArguments.cend();
- QStringList::const_iterator argsIt = lstjsDebugArguments.cbegin();
- for (; argsIt != argsItEnd; ++argsIt) {
- const QString strArgument = *argsIt;
+ const auto lstjsDebugArguments = args.splitRef(QLatin1Char(','));
+ for (auto argsIt = lstjsDebugArguments.begin(), argsItEnd = lstjsDebugArguments.end(); argsIt != argsItEnd; ++argsIt) {
+ const QStringRef &strArgument = *argsIt;
if (strArgument.startsWith(QLatin1String("port:"))) {
- portFrom = strArgument.midRef(5).toInt(&ok);
+ portFrom = strArgument.mid(5).toInt(&ok);
portTo = portFrom;
- QStringList::const_iterator argsNext = argsIt + 1;
+ const auto argsNext = argsIt + 1;
if (argsNext == argsItEnd)
break;
- const QString nextArgument = *argsNext;
-
- // Don't use QStringLiteral here. QRegExp has a global cache and will save an implicitly
- // shared copy of the passed string. That copy isn't properly detached when the library
- // is unloaded if the original string lives in the library's .rodata
- if (ok && nextArgument.contains(QRegExp(QLatin1String("^\\s*\\d+\\s*$")))) {
- portTo = nextArgument.toInt(&ok);
- ++argsIt;
+ if (ok) {
+ const QString nextArgument = argsNext->toString();
+
+ // Don't use QStringLiteral here. QRegExp has a global cache and will save an implicitly
+ // shared copy of the passed string. That copy isn't properly detached when the library
+ // is unloaded if the original string lives in the library's .rodata
+ if (nextArgument.contains(QRegExp(QLatin1String("^\\s*\\d+\\s*$")))) {
+ portTo = nextArgument.toInt(&ok);
+ ++argsIt;
+ }
}
} else if (strArgument.startsWith(QLatin1String("host:"))) {
- hostAddress = strArgument.mid(5);
+ hostAddress = strArgument.mid(5).toString();
} else if (strArgument == QLatin1String("block")) {
block = true;
} else if (strArgument.startsWith(QLatin1String("file:"))) {
- fileName = strArgument.mid(5);
+ fileName = strArgument.mid(5).toString();
ok = !fileName.isEmpty();
} else if (strArgument.startsWith(QLatin1String("services:"))) {
- services.append(strArgument.mid(9));
+ services.append(strArgument.mid(9).toString());
} else if (!services.isEmpty()) {
- services.append(strArgument);
+ services.append(strArgument.toString());
} else {
const QString message = tr("QML Debugger: Invalid argument \"%1\" detected."
- " Ignoring the same.").arg(strArgument);
+ " Ignoring the same.").arg(strArgument.toString());
qWarning("%s", qPrintable(message));
}
}
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index 065e91109b..eaf0e72296 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -250,8 +250,8 @@ void Document::collectTypeReferences()
void Document::removeScriptPragmas(QString &script)
{
- const QString pragma(QLatin1String("pragma"));
- const QString library(QLatin1String("library"));
+ const QLatin1String pragma("pragma");
+ const QLatin1String library("library");
QQmlJS::Lexer l(0);
l.setCode(script, 0);
@@ -269,7 +269,7 @@ void Document::removeScriptPragmas(QString &script)
if (token != QQmlJSGrammar::T_PRAGMA ||
l.tokenStartLine() != startLine ||
- script.mid(l.tokenOffset(), l.tokenLength()) != pragma)
+ script.midRef(l.tokenOffset(), l.tokenLength()) != pragma)
return;
token = l.lex();
@@ -278,7 +278,7 @@ void Document::removeScriptPragmas(QString &script)
l.tokenStartLine() != startLine)
return;
- QString pragmaValue = script.mid(l.tokenOffset(), l.tokenLength());
+ const QStringRef pragmaValue = script.midRef(l.tokenOffset(), l.tokenLength());
int endOffset = l.tokenLength() + l.tokenOffset();
token = l.lex();
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index a71793f2b6..da00496cb2 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -179,16 +179,16 @@ bool QQmlTypeCompiler::compile()
for (int scriptIndex = 0; scriptIndex < scripts.count(); ++scriptIndex) {
const QQmlTypeData::ScriptReference &script = scripts.at(scriptIndex);
- QString qualifier = script.qualifier;
+ QStringRef qualifier(&script.qualifier);
QString enclosingNamespace;
const int lastDotIndex = qualifier.lastIndexOf(QLatin1Char('.'));
if (lastDotIndex != -1) {
- enclosingNamespace = qualifier.left(lastDotIndex);
+ enclosingNamespace = qualifier.left(lastDotIndex).toString();
qualifier = qualifier.mid(lastDotIndex+1);
}
- compiledData->importCache->add(qualifier, scriptIndex, enclosingNamespace);
+ compiledData->importCache->add(qualifier.toString(), scriptIndex, enclosingNamespace);
QQmlScriptData *scriptData = script.script->scriptData();
scriptData->addref();
compiledData->scripts << scriptData;
@@ -624,7 +624,7 @@ bool QQmlPropertyCacheCreator::createMetaObject(int objectIndex, const QmlIR::Ob
QString path = compiler->url().path();
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
if (lastSlash > -1) {
- QString nameBase = path.mid(lastSlash + 1, path.length()-lastSlash-5);
+ const QStringRef nameBase = path.midRef(lastSlash + 1, path.length() - lastSlash - 5);
if (!nameBase.isEmpty() && nameBase.at(0).isUpper())
newClassName = nameBase.toUtf8() + "_QMLTYPE_" +
QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1));
@@ -1163,10 +1163,10 @@ struct StaticQtMetaObject : public QObject
{ return &staticQtMetaObject; }
};
-bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
+bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &enumName, int enumValue, bool isQtObject)
{
if (enumName.length() > 0 && enumName[0].isLower() && !isQtObject) {
- COMPILE_EXCEPTION(binding, tr("Invalid property assignment: Enum value \"%1\" cannot start with a lowercase letter").arg(enumName));
+ COMPILE_EXCEPTION(binding, tr("Invalid property assignment: Enum value \"%1\" cannot start with a lowercase letter").arg(enumName.toString()));
}
binding->type = QV4::CompiledData::Binding::Type_Number;
binding->value.d = (double)enumValue;
@@ -1197,7 +1197,7 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj,
QHashedStringRef typeName(string.constData(), dot);
const bool isQtObject = (typeName == QLatin1String("Qt"));
- QString enumValue = string.mid(dot+1);
+ const QStringRef enumValue = string.midRef(dot + 1);
if (isIntProp) {
// Allow enum assignment to ints.
diff --git a/src/qml/compiler/qqmltypecompiler_p.h b/src/qml/compiler/qqmltypecompiler_p.h
index 240f591f91..273ba01a88 100644
--- a/src/qml/compiler/qqmltypecompiler_p.h
+++ b/src/qml/compiler/qqmltypecompiler_p.h
@@ -196,7 +196,11 @@ public:
bool resolveEnumBindings();
private:
- bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject);
+ bool assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &enumName, int enumValue, bool isQtObject);
+ bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject)
+ {
+ return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject);
+ }
bool tryQualifiedEnumAssignment(const QmlIR::Object *obj, const QQmlPropertyCache *propertyCache,
const QQmlPropertyData *prop,
QmlIR::Binding *binding);
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 4d0361302e..a63f35152a 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -221,8 +221,8 @@ QString Binding::valueAsString(const Unit *unit) const
// This code must match that in the qsTr() implementation
const QString &path = unit->stringAt(unit->sourceFileIndex);
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
- QString context = (lastSlash > -1) ? path.mid(lastSlash + 1, path.length()-lastSlash-5) :
- QString();
+ QStringRef context = (lastSlash > -1) ? path.midRef(lastSlash + 1, path.length() - lastSlash - 5)
+ : QStringRef();
QByteArray contextUtf8 = context.toUtf8();
QByteArray comment = unit->stringAt(value.translationData.commentIndex).toUtf8();
QByteArray text = unit->stringAt(stringIndex).toUtf8();
diff --git a/src/qml/qml/qqmlerror.cpp b/src/qml/qml/qqmlerror.cpp
index 47c85c907c..74ceeabeb4 100644
--- a/src/qml/qml/qqmlerror.cpp
+++ b/src/qml/qml/qqmlerror.cpp
@@ -43,6 +43,7 @@
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
#include <QtCore/qstringlist.h>
+#include <QtCore/qvector.h>
#include <private/qv4errorobject_p.h>
@@ -288,11 +289,11 @@ QDebug operator<<(QDebug debug, const QQmlError &error)
stream.setCodec("UTF-8");
#endif
const QString code = stream.readAll();
- const QStringList lines = code.split(QLatin1Char('\n'));
+ const auto lines = code.splitRef(QLatin1Char('\n'));
if (lines.count() >= error.line()) {
- const QString &line = lines.at(error.line() - 1);
- debug << "\n " << qPrintable(line);
+ const QStringRef &line = lines.at(error.line() - 1);
+ debug << "\n " << line.toLocal8Bit().constData();
if(error.column() > 0) {
int column = qMax(0, error.column() - 1);
diff --git a/src/qml/qml/qqmlfile.cpp b/src/qml/qml/qqmlfile.cpp
index ea4e9a1013..5fe3cba5c3 100644
--- a/src/qml/qml/qqmlfile.cpp
+++ b/src/qml/qml/qqmlfile.cpp
@@ -583,7 +583,7 @@ QString QQmlFile::urlToLocalFileOrQrc(const QString& url)
{
if (url.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive)) {
if (url.length() > 4)
- return QLatin1Char(':') + url.mid(4);
+ return QLatin1Char(':') + url.midRef(4);
return QString();
}
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index ec29e600ed..2a1717f190 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -85,12 +85,11 @@ QString resolveLocalUrl(const QString &url, const QString &relative)
} else if (relative.at(0) == Slash || !url.contains(Slash)) {
return relative;
} else {
- QString base(url.left(url.lastIndexOf(Slash) + 1));
-
+ const QStringRef baseRef = url.leftRef(url.lastIndexOf(Slash) + 1);
if (relative == QLatin1String("."))
- return base;
+ return baseRef.toString();
- base.append(relative);
+ QString base = baseRef + relative;
// Remove any relative directory elements in the path
int length = base.length();
@@ -815,11 +814,11 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
QString u1 = import->url;
QString u2 = import2->url;
if (base) {
- QString b = *base;
+ QStringRef b(base);
int dot = b.lastIndexOf(Dot);
if (dot >= 0) {
b = b.left(dot+1);
- QString l = b.left(dot);
+ QStringRef l = b.left(dot);
if (u1.startsWith(b))
u1 = u1.mid(b.count());
else if (u1 == l)
@@ -1173,11 +1172,11 @@ bool QQmlImportsPrivate::locateQmldir(const QString &uri, int vmaj, int vmin, QQ
QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
if (!absoluteFilePath.isEmpty()) {
QString url;
- QString absolutePath = absoluteFilePath.left(absoluteFilePath.lastIndexOf(Slash)+1);
+ const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1);
if (absolutePath.at(0) == Colon)
url = QLatin1String("qrc://") + absolutePath.mid(1);
else
- url = QUrl::fromLocalFile(absolutePath).toString();
+ url = QUrl::fromLocalFile(absolutePath.toString()).toString();
QQmlImportDatabase::QmldirCache *cache = new QQmlImportDatabase::QmldirCache;
cache->versionMajor = vmaj;
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 22de5e1ae9..df2ff05de1 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -58,6 +58,7 @@
#include <private/qv4functionobject_p.h>
#include <QStringList>
+#include <QVector>
#include <private/qmetaobject_p.h>
#include <private/qqmlvaluetypewrapper_p.h>
#include <QtCore/qdebug.h>
@@ -240,14 +241,14 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
QQmlTypeNameCache *typeNameCache = context?context->imports:0;
- QStringList path = name.split(QLatin1Char('.'));
+ const auto path = name.splitRef(QLatin1Char('.'));
if (path.isEmpty()) return;
QObject *currentObject = obj;
// Everything up to the last property must be an "object type" property
for (int ii = 0; ii < path.count() - 1; ++ii) {
- const QString &pathName = path.at(ii);
+ const QStringRef &pathName = path.at(ii);
if (typeNameCache) {
QQmlTypeNameCache::Result r = typeNameCache->query(pathName);
@@ -284,7 +285,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
QQmlPropertyData local;
QQmlPropertyData *property =
- QQmlPropertyCache::property(engine, currentObject, pathName, context, local);
+ QQmlPropertyCache::property(engine, currentObject, pathName.toString(), context, local);
if (!property) return; // Not a property
if (property->isFunction())
@@ -324,14 +325,14 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
}
- const QString &terminal = path.last();
+ const QStringRef &terminal = path.last();
if (terminal.count() >= 3 &&
terminal.at(0) == QLatin1Char('o') &&
terminal.at(1) == QLatin1Char('n') &&
terminal.at(2).isUpper()) {
- QString signalName = terminal.mid(2);
+ QString signalName = terminal.mid(2).toString();
signalName[0] = signalName.at(0).toLower();
// XXX - this code treats methods as signals
@@ -376,13 +377,14 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
}
// Property
+ const QString terminalString = terminal.toString();
QQmlPropertyData local;
QQmlPropertyData *property =
- QQmlPropertyCache::property(engine, currentObject, terminal, context, local);
+ QQmlPropertyCache::property(engine, currentObject, terminalString, context, local);
if (property && !property->isFunction()) {
object = currentObject;
core = *property;
- nameCache = terminal;
+ nameCache = terminalString;
isNameCached = true;
}
}
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp
index 527b8aad55..0e7b0c1b14 100644
--- a/src/qml/types/qqmldelegatemodel.cpp
+++ b/src/qml/types/qqmldelegatemodel.cpp
@@ -1042,7 +1042,7 @@ QString QQmlDelegateModelPrivate::stringValue(Compositor::Group group, int index
return QString();
int from = dot+1;
dot = name.indexOf(QLatin1Char('.'), from);
- value = obj->property(name.mid(from, dot-from).toUtf8());
+ value = obj->property(name.midRef(from, dot - from).toUtf8());
}
return value.toString();
}
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp
index 9ba93a1241..bc26a19033 100644
--- a/src/qmltest/quicktest.cpp
+++ b/src/qmltest/quicktest.cpp
@@ -352,7 +352,7 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD
QTestRootObject::instance()->init();
QString path = fi.absoluteFilePath();
if (path.startsWith(QLatin1String(":/")))
- view->setSource(QUrl(QLatin1String("qrc:") + path.mid(2)));
+ view->setSource(QUrl(QLatin1String("qrc:") + path.midRef(2)));
else
view->setSource(QUrl::fromLocalFile(path));
diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp
index 734cadf49a..1b0670aabf 100644
--- a/src/quick/items/context2d/qquickcontext2d.cpp
+++ b/src/quick/items/context2d/qquickcontext2d.cpp
@@ -65,6 +65,7 @@
#include <private/qv4scopedvalue_p.h>
#include <QtCore/qmath.h>
+#include <QtCore/qvector.h>
#include <QtCore/private/qnumeric_p.h>
#include <QtCore/QRunnable>
#include <QtGui/qguiapplication.h>
@@ -200,7 +201,7 @@ QColor qt_color_from_string(const QV4::Value &name)
return QColor();
}
-static int qParseFontSizeFromToken(const QString &fontSizeToken, bool &ok)
+static int qParseFontSizeFromToken(const QStringRef &fontSizeToken, bool &ok)
{
ok = false;
float size = fontSizeToken.trimmed().toFloat(&ok);
@@ -216,11 +217,11 @@ static int qParseFontSizeFromToken(const QString &fontSizeToken, bool &ok)
\c true if successful. If the font size is invalid, \c false is returned
and a warning is printed.
*/
-static bool qSetFontSizeFromToken(QFont &font, const QString &fontSizeToken)
+static bool qSetFontSizeFromToken(QFont &font, const QStringRef &fontSizeToken)
{
- const QString trimmedToken = fontSizeToken.trimmed();
- const QString unitStr = trimmedToken.right(2);
- const QString value = trimmedToken.left(trimmedToken.size() - 2);
+ const QStringRef trimmedToken = fontSizeToken.trimmed();
+ const QStringRef unitStr = trimmedToken.right(2);
+ const QStringRef value = trimmedToken.left(trimmedToken.size() - 2);
bool ok = false;
int size = 0;
if (unitStr == QLatin1String("px")) {
@@ -246,7 +247,7 @@ static bool qSetFontSizeFromToken(QFont &font, const QString &fontSizeToken)
each family is separated by spaces. Families with spaces in their name
must be quoted.
*/
-static QStringList qExtractFontFamiliesFromString(const QString &fontFamiliesString)
+static QStringList qExtractFontFamiliesFromString(const QStringRef &fontFamiliesString)
{
QStringList extractedFamilies;
int quoteIndex = -1;
@@ -259,7 +260,7 @@ static QStringList qExtractFontFamiliesFromString(const QString &fontFamiliesStr
} else {
if (ch == fontFamiliesString.at(quoteIndex)) {
// Found the matching quote. +1/-1 because we don't want the quote as part of the name.
- const QString family = fontFamiliesString.mid(quoteIndex + 1, index - quoteIndex - 1);
+ const QString family = fontFamiliesString.mid(quoteIndex + 1, index - quoteIndex - 1).toString();
extractedFamilies.push_back(family);
currentFamily.clear();
quoteIndex = -1;
@@ -390,16 +391,17 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
fontSizeEnd += 3;
QFont newFont;
- if (!qSetFontSizeFromToken(newFont, fontString.mid(fontSizeStart, fontSizeEnd - fontSizeStart)))
+ if (!qSetFontSizeFromToken(newFont, fontString.midRef(fontSizeStart, fontSizeEnd - fontSizeStart)))
return currentFont;
// We don't want to parse the size twice, so remove it now.
QString remainingFontString = fontString;
remainingFontString.remove(fontSizeStart, fontSizeEnd - fontSizeStart);
+ QStringRef remainingFontStringRef(&remainingFontString);
// Next, we have to take any font families out, as QString::split() will ruin quoted family names.
- const QString fontFamiliesString = remainingFontString.mid(fontSizeStart);
- remainingFontString.chop(remainingFontString.length() - fontSizeStart);
+ const QStringRef fontFamiliesString = remainingFontStringRef.mid(fontSizeStart);
+ remainingFontStringRef.truncate(fontSizeStart);
QStringList fontFamilies = qExtractFontFamiliesFromString(fontFamiliesString);
if (fontFamilies.isEmpty()) {
return currentFont;
@@ -408,16 +410,16 @@ static QFont qt_font_from_string(const QString& fontString, const QFont &current
return currentFont;
// Now that we've removed the messy parts, we can split the font string on spaces.
- const QString trimmedTokensStr = remainingFontString.trimmed();
+ const QStringRef trimmedTokensStr = remainingFontStringRef.trimmed();
if (trimmedTokensStr.isEmpty()) {
// No optional properties.
return newFont;
}
- const QStringList tokens = trimmedTokensStr.split(QLatin1Char(' '));
+ const auto tokens = trimmedTokensStr.split(QLatin1Char(' '));
int usedTokens = NoTokens;
// Optional properties can be in any order, but font-size and font-family must be last.
- for (const QString &token : tokens) {
+ for (const QStringRef &token : tokens) {
if (token.compare(QLatin1String("normal")) == 0) {
if (!(usedTokens & FontStyle) || !(usedTokens & FontVariant) || !(usedTokens & FontWeight)) {
// Could be font-style, font-variant or font-weight.
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp
index f0bbb1e732..a56d0fc06e 100644
--- a/src/quick/items/qquickpathview.cpp
+++ b/src/quick/items/qquickpathview.cpp
@@ -1910,7 +1910,7 @@ void QQuickPathView::refill()
if (lcItemViewDelegateLifecycle().isDebugEnabled()) {
QQuickText *text = qmlobject_cast<QQuickText*>(item);
if (text)
- qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ": QQuickText" << text->objectName() << text->text().left(40);
+ qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ": QQuickText" << text->objectName() << text->text().leftRef(40);
else
qCDebug(lcItemViewDelegateLifecycle) << "idx" << idx << "@" << pos << ":" << item;
}
diff --git a/src/quick/items/qquickscalegrid.cpp b/src/quick/items/qquickscalegrid.cpp
index f860c08bad..d7a0f1b681 100644
--- a/src/quick/items/qquickscalegrid.cpp
+++ b/src/quick/items/qquickscalegrid.cpp
@@ -136,39 +136,38 @@ QQuickGridScaledImage::QQuickGridScaledImage(QIODevice *data)
if (colonId <= 0)
return;
- QStringList list;
- list.append(line.left(colonId).trimmed());
- list.append(line.mid(colonId+1).trimmed());
-
- if (list[0] == QLatin1String("border.left"))
- l = list[1].toInt();
- else if (list[0] == QLatin1String("border.right"))
- r = list[1].toInt();
- else if (list[0] == QLatin1String("border.top"))
- t = list[1].toInt();
- else if (list[0] == QLatin1String("border.bottom"))
- b = list[1].toInt();
- else if (list[0] == QLatin1String("source"))
- imgFile = list[1];
- else if (list[0] == QLatin1String("horizontalTileRule") || list[0] == QLatin1String("horizontalTileMode"))
- _h = stringToRule(list[1]);
- else if (list[0] == QLatin1String("verticalTileRule") || list[0] == QLatin1String("verticalTileMode"))
- _v = stringToRule(list[1]);
+ const QStringRef property = line.leftRef(colonId).trimmed();
+ QStringRef value = line.midRef(colonId + 1).trimmed();
+
+ if (property == QLatin1String("border.left")) {
+ l = value.toInt();
+ } else if (property == QLatin1String("border.right")) {
+ r = value.toInt();
+ } else if (property == QLatin1String("border.top")) {
+ t = value.toInt();
+ } else if (property == QLatin1String("border.bottom")) {
+ b = value.toInt();
+ } else if (property == QLatin1String("source")) {
+ if (value.startsWith(QLatin1Char('"')) && value.endsWith(QLatin1Char('"')))
+ value = value.mid(1, value.size() - 2); // remove leading/trailing quotes.
+ imgFile = value.toString();
+ } else if (property == QLatin1String("horizontalTileRule") || property == QLatin1String("horizontalTileMode")) {
+ _h = stringToRule(value);
+ } else if (property == QLatin1String("verticalTileRule") || property == QLatin1String("verticalTileMode")) {
+ _v = stringToRule(value);
+ }
}
if (l < 0 || r < 0 || t < 0 || b < 0 || imgFile.isEmpty())
return;
_l = l; _r = r; _t = t; _b = b;
-
_pix = imgFile;
- if (_pix.startsWith(QLatin1Char('"')) && _pix.endsWith(QLatin1Char('"')))
- _pix = _pix.mid(1, _pix.size() - 2); // remove leading/trailing quotes.
}
-QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QString &s)
+QQuickBorderImage::TileMode QQuickGridScaledImage::stringToRule(const QStringRef &s)
{
- QString string = s;
+ QStringRef string = s;
if (string.startsWith(QLatin1Char('"')) && string.endsWith(QLatin1Char('"')))
string = string.mid(1, string.size() - 2); // remove leading/trailing quotes.
diff --git a/src/quick/items/qquickscalegrid_p_p.h b/src/quick/items/qquickscalegrid_p_p.h
index a424002dfb..7f6a31a7bd 100644
--- a/src/quick/items/qquickscalegrid_p_p.h
+++ b/src/quick/items/qquickscalegrid_p_p.h
@@ -116,7 +116,7 @@ public:
QString pixmapUrl() const;
private:
- static QQuickBorderImage::TileMode stringToRule(const QString &);
+ static QQuickBorderImage::TileMode stringToRule(const QStringRef &);
private:
int _l;
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index ab7a0f02dd..504dece0d1 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -1874,7 +1874,7 @@ QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property, QVaria
return QVariant(d->m_text.mid(d->m_cursor));
case Qt::ImTextBeforeCursor:
if (argument.isValid())
- return QVariant(d->m_text.left(d->m_cursor).right(argument.toInt()));
+ return QVariant(d->m_text.leftRef(d->m_cursor).right(argument.toInt()).toString());
return QVariant(d->m_text.left(d->m_cursor));
default:
return QQuickItem::inputMethodQuery(property);
diff --git a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
index ec1d316f78..caa296451e 100644
--- a/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
+++ b/src/quick/scenegraph/util/qsgshadersourcebuilder.cpp
@@ -382,9 +382,9 @@ QString QSGShaderSourceBuilder::resolveShaderPath(const QString &path) const
int idx = path.lastIndexOf(QLatin1Char('.'));
QString resolvedPath;
if (idx != -1)
- resolvedPath = path.left(idx)
- + QStringLiteral("_core")
- + path.right(path.length() - idx);
+ resolvedPath = path.leftRef(idx)
+ + QLatin1String("_core")
+ + path.rightRef(path.length() - idx);
return resolvedPath;
}
}
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp
index adf8f600a0..741a583803 100644
--- a/src/quick/util/qquickanimation.cpp
+++ b/src/quick/util/qquickanimation.cpp
@@ -986,7 +986,7 @@ void QQuickScriptActionPrivate::debugAction(QDebug d, int indentLevel) const
QByteArray ind(indentLevel, ' ');
QString exprStr = expr.expression();
int endOfFirstLine = exprStr.indexOf('\n');
- d << "\n" << ind.constData() << exprStr.left(endOfFirstLine);
+ d << "\n" << ind.constData() << exprStr.leftRef(endOfFirstLine);
if (endOfFirstLine != -1 && endOfFirstLine < exprStr.length())
d << "...";
}
diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp
index ef54917434..be4c968ab2 100644
--- a/src/quick/util/qquickglobal.cpp
+++ b/src/quick/util/qquickglobal.cpp
@@ -172,8 +172,8 @@ public:
int index = s.indexOf(QLatin1Char(','));
bool xGood, yGood;
- float xCoord = s.left(index).toFloat(&xGood);
- float yCoord = s.mid(index+1).toFloat(&yGood);
+ float xCoord = s.leftRef(index).toFloat(&xGood);
+ float yCoord = s.midRef(index + 1).toFloat(&yGood);
if (xGood && yGood) {
if (ok) *ok = true;
@@ -192,9 +192,9 @@ public:
int index2 = s.indexOf(QLatin1Char(','), index+1);
bool xGood, yGood, zGood;
- float xCoord = s.left(index).toFloat(&xGood);
- float yCoord = s.mid(index+1, index2-index-1).toFloat(&yGood);
- float zCoord = s.mid(index2+1).toFloat(&zGood);
+ float xCoord = s.leftRef(index).toFloat(&xGood);
+ float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood);
+ float zCoord = s.midRef(index2 + 1).toFloat(&zGood);
if (xGood && yGood && zGood) {
if (ok) *ok = true;
@@ -214,10 +214,10 @@ public:
int index3 = s.indexOf(QLatin1Char(','), index2+1);
bool xGood, yGood, zGood, wGood;
- float xCoord = s.left(index).toFloat(&xGood);
- float yCoord = s.mid(index+1, index2-index-1).toFloat(&yGood);
- float zCoord = s.mid(index2+1, index3-index2-1).toFloat(&zGood);
- float wCoord = s.mid(index3+1).toFloat(&wGood);
+ float xCoord = s.leftRef(index).toFloat(&xGood);
+ float yCoord = s.midRef(index + 1, index2 - index - 1).toFloat(&yGood);
+ float zCoord = s.midRef(index2 + 1, index3 - index2 - 1).toFloat(&zGood);
+ float wCoord = s.midRef(index3 + 1).toFloat(&wGood);
if (xGood && yGood && zGood && wGood) {
if (ok) *ok = true;
@@ -257,10 +257,10 @@ public:
if (s.count(QLatin1Char(',')) == 15) {
float matValues[16];
bool vOK = true;
- QString mutableStr = s;
+ QStringRef mutableStr(&s);
for (int i = 0; vOK && i < 16; ++i) {
int cidx = mutableStr.indexOf(QLatin1Char(','));
- matValues[i] = mutableStr.leftRef(cidx).toDouble(&vOK);
+ matValues[i] = mutableStr.left(cidx).toDouble(&vOK);
mutableStr = mutableStr.mid(cidx + 1);
}
diff --git a/src/quick/util/qquickstategroup.cpp b/src/quick/util/qquickstategroup.cpp
index 791e38e45d..c163b401fb 100644
--- a/src/quick/util/qquickstategroup.cpp
+++ b/src/quick/util/qquickstategroup.cpp
@@ -47,6 +47,7 @@
#include <QtCore/qstringbuilder.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h>
+#include <QtCore/qvector.h>
#include <private/qobject_p.h>
#include <qqmlinfo.h>
@@ -379,28 +380,29 @@ QQuickTransition *QQuickStateGroupPrivate::findTransition(const QString &from, c
(t->fromState() == QLatin1String("*") &&
t->toState() == QLatin1String("*"))))
break;
- QStringList fromState;
- QStringList toState;
+ const QString fromStateStr = t->fromState();
+ const QString toStateStr = t->toState();
- fromState = t->fromState().split(QLatin1Char(','));
+ QVector<QStringRef> fromState = fromStateStr.splitRef(QLatin1Char(','));
for (int jj = 0; jj < fromState.count(); ++jj)
fromState[jj] = fromState.at(jj).trimmed();
- toState = t->toState().split(QLatin1Char(','));
+ QVector<QStringRef> toState = toStateStr.splitRef(QLatin1Char(','));
for (int jj = 0; jj < toState.count(); ++jj)
toState[jj] = toState.at(jj).trimmed();
if (ii == 1)
qSwap(fromState, toState);
int tScore = 0;
- if (fromState.contains(from))
+ const QString asterisk = QStringLiteral("*");
+ if (fromState.contains(QStringRef(&from)))
tScore += 2;
- else if (fromState.contains(QLatin1String("*")))
+ else if (fromState.contains(QStringRef(&asterisk)))
tScore += 1;
else
continue;
- if (toState.contains(to))
+ if (toState.contains(QStringRef(&to)))
tScore += 2;
- else if (toState.contains(QLatin1String("*")))
+ else if (toState.contains(QStringRef(&asterisk)))
tScore += 1;
else
continue;