From c03d9c49d3367f01491f297e606083d63b1b36ce Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 7 Jun 2016 17:15:07 +0300 Subject: Qml: replace QStringLiteral with QL1S ... or with QL1C in such cases: - if there is overloaded function - in QStringBuilder expressions Saves ~1.5 KB in text size. Build config: ubuntu 16.04 x64, gcc 5.3 Change-Id: Icc0789f1c244ce20a3182494b0c7f35c9d77e41d Reviewed-by: Shawn Rutledge Reviewed-by: Ulf Hermann --- src/qml/compiler/qv4jsir.cpp | 10 +++++----- src/qml/jsruntime/qv4dateobject.cpp | 2 +- src/qml/jsruntime/qv4engine.cpp | 4 ++-- src/qml/jsruntime/qv4globalobject.cpp | 2 +- src/qml/jsruntime/qv4jsonobject.cpp | 35 +++++++++++++++++++---------------- src/qml/jsruntime/qv4object.cpp | 2 +- src/qml/jsruntime/qv4vme_moth.cpp | 14 +++++++------- src/qml/qml/qqmlboundsignal.cpp | 4 ++-- src/qml/qml/qqmlengine.cpp | 2 +- src/qml/qml/qqmlimport.cpp | 6 +++--- src/qml/qml/qqmlpropertycache.cpp | 2 +- src/qml/types/qqmldelegatemodel.cpp | 8 ++++---- 12 files changed, 47 insertions(+), 44 deletions(-) (limited to 'src/qml') diff --git a/src/qml/compiler/qv4jsir.cpp b/src/qml/compiler/qv4jsir.cpp index 74c4f91f2b..c6a6c95cd8 100644 --- a/src/qml/compiler/qv4jsir.cpp +++ b/src/qml/compiler/qv4jsir.cpp @@ -929,15 +929,15 @@ QString IRPrinter::escape(const QString &s) for (int i = 0; i < s.length(); ++i) { const QChar ch = s.at(i); if (ch == QLatin1Char('\n')) - r += QStringLiteral("\\n"); + r += QLatin1String("\\n"); else if (ch == QLatin1Char('\r')) - r += QStringLiteral("\\r"); + r += QLatin1String("\\r"); else if (ch == QLatin1Char('\\')) - r += QStringLiteral("\\\\"); + r += QLatin1String("\\\\"); else if (ch == QLatin1Char('"')) - r += QStringLiteral("\\\""); + r += QLatin1String("\\\""); else if (ch == QLatin1Char('\'')) - r += QStringLiteral("\\'"); + r += QLatin1String("\\'"); else r += ch; } diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 6acc76cdd8..df648ba9ee 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -565,7 +565,7 @@ static inline QString ToString(double t) { if (std::isnan(t)) return QStringLiteral("Invalid Date"); - QString str = ToDateTime(t, Qt::LocalTime).toString() + QStringLiteral(" GMT"); + QString str = ToDateTime(t, Qt::LocalTime).toString() + QLatin1String(" GMT"); double tzoffset = LocalTZA + DaylightSavingTA(t); if (tzoffset) { int hours = static_cast(::fabs(tzoffset) / 1000 / 60 / 60); diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 4a26b8b662..fe2d4e6575 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -969,7 +969,7 @@ ReturnedValue ExecutionEngine::throwReferenceError(const Value &value) { Scope scope(this); ScopedString s(scope, value.toString(this)); - QString msg = s->toQString() + QStringLiteral(" is not defined"); + QString msg = s->toQString() + QLatin1String(" is not defined"); ScopedObject error(scope, newReferenceErrorObject(msg)); return throwError(error); } @@ -993,7 +993,7 @@ ReturnedValue ExecutionEngine::throwRangeError(const Value &value) { Scope scope(this); ScopedString s(scope, value.toString(this)); - QString msg = s->toQString() + QStringLiteral(" out of range"); + QString msg = s->toQString() + QLatin1String(" out of range"); ScopedObject error(scope, newRangeErrorObject(msg)); return throwError(error); } diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index d8130c1cac..b88e271a26 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -520,7 +520,7 @@ ReturnedValue GlobalFunctions::method_parseFloat(CallContext *ctx) if (trimmed.startsWith(QLatin1String("Infinity")) || trimmed.startsWith(QLatin1String("+Infinity"))) return Encode(Q_INFINITY); - if (trimmed.startsWith(QStringLiteral("-Infinity"))) + if (trimmed.startsWith(QLatin1String("-Infinity"))) return Encode(-Q_INFINITY); QByteArray ba = trimmed.toLatin1(); bool ok; diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 7661dd1903..5b665d8836 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -643,34 +643,37 @@ struct Stringify static QString quote(const QString &str) { - QString product = QStringLiteral("\""); - for (int i = 0; i < str.length(); ++i) { + QString product; + const int length = str.length(); + product.reserve(length + 2); + product += QLatin1Char('"'); + for (int i = 0; i < length; ++i) { QChar c = str.at(i); switch (c.unicode()) { case '"': - product += QStringLiteral("\\\""); + product += QLatin1String("\\\""); break; case '\\': - product += QStringLiteral("\\\\"); + product += QLatin1String("\\\\"); break; case '\b': - product += QStringLiteral("\\b"); + product += QLatin1String("\\b"); break; case '\f': - product += QStringLiteral("\\f"); + product += QLatin1String("\\f"); break; case '\n': - product += QStringLiteral("\\n"); + product += QLatin1String("\\n"); break; case '\r': - product += QStringLiteral("\\r"); + product += QLatin1String("\\r"); break; case '\t': - product += QStringLiteral("\\t"); + product += QLatin1String("\\t"); break; default: if (c.unicode() <= 0x1f) { - product += QStringLiteral("\\u00"); + product += QLatin1String("\\u00"); product += (c.unicode() > 0xf ? QLatin1Char('1') : QLatin1Char('0')) + QLatin1Char("0123456789abcdef"[c.unicode() & 0xf]); } else { @@ -806,10 +809,10 @@ QString Stringify::JO(Object *o) if (partial.isEmpty()) { result = QStringLiteral("{}"); } else if (gap.isEmpty()) { - result = QStringLiteral("{") + partial.join(QLatin1Char(',')) + QLatin1Char('}'); + result = QLatin1Char('{') + partial.join(QLatin1Char(',')) + QLatin1Char('}'); } else { - QString separator = QStringLiteral(",\n") + indent; - result = QStringLiteral("{\n") + indent + partial.join(separator) + QLatin1Char('\n') + QString separator = QLatin1String(",\n") + indent; + result = QLatin1String("{\n") + indent + partial.join(separator) + QLatin1Char('\n') + stepback + QLatin1Char('}'); } @@ -852,10 +855,10 @@ QString Stringify::JA(ArrayObject *a) if (partial.isEmpty()) { result = QStringLiteral("[]"); } else if (gap.isEmpty()) { - result = QStringLiteral("[") + partial.join(QLatin1Char(',')) + QStringLiteral("]"); + result = QLatin1Char('[') + partial.join(QLatin1Char(',')) + QLatin1Char(']'); } else { - QString separator = QStringLiteral(",\n") + indent; - result = QStringLiteral("[\n") + indent + partial.join(separator) + QStringLiteral("\n") + stepback + QStringLiteral("]"); + QString separator = QLatin1String(",\n") + indent; + result = QLatin1String("[\n") + indent + partial.join(separator) + QLatin1Char('\n') + stepback + QLatin1Char(']'); } indent = stepback; diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 0fc5f95dad..aeb185049f 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -754,7 +754,7 @@ void Object::internalPut(String *name, const Value &value) reject: if (engine()->current->strictMode) { - QString message = QStringLiteral("Cannot assign to read-only property \"") + + QString message = QLatin1String("Cannot assign to read-only property \"") + name->toQString() + QLatin1Char('\"'); engine()->throwTypeError(message); } diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index 9ad21305f7..99aa0ef652 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -203,7 +203,7 @@ int qt_v4DebuggerHook(const char *json) QJsonDocument doc = QJsonDocument::fromJson(json); QJsonObject ob = doc.object(); - QByteArray command = ob.value(QStringLiteral("command")).toString().toUtf8(); + QByteArray command = ob.value(QLatin1String("command")).toString().toUtf8(); if (command == "protocolVersion") { return ProtocolVersion; // Version number. @@ -217,17 +217,17 @@ int qt_v4DebuggerHook(const char *json) if (command == "insertBreakpoint") { Breakpoint bp; bp.bpNumber = ++qt_v4BreakpointCount; - bp.lineNumber = ob.value(QStringLiteral("lineNumber")).toString().toInt(); - bp.engineName = ob.value(QStringLiteral("engineName")).toString(); - bp.fullName = ob.value(QStringLiteral("fullName")).toString(); - bp.condition = ob.value(QStringLiteral("condition")).toString(); + bp.lineNumber = ob.value(QLatin1String("lineNumber")).toString().toInt(); + bp.engineName = ob.value(QLatin1String("engineName")).toString(); + bp.fullName = ob.value(QLatin1String("fullName")).toString(); + bp.condition = ob.value(QLatin1String("condition")).toString(); qt_v4Breakpoints.append(bp); return bp.bpNumber; } if (command == "removeBreakpoint") { - int lineNumber = ob.value(QStringLiteral("lineNumber")).toString().toInt(); - QString fullName = ob.value(QStringLiteral("fullName")).toString(); + int lineNumber = ob.value(QLatin1String("lineNumber")).toString().toInt(); + QString fullName = ob.value(QLatin1String("fullName")).toString(); if (qt_v4Breakpoints.last().matches(fullName, lineNumber)) { qt_v4Breakpoints.removeLast(); return Success; diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index ab968065a4..266a5e5366 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -81,7 +81,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, // Add some leading whitespace to account for the binding's column offset. // It's 2 off because a, we start counting at 1 and b, the '(' below is not counted. function.fill(QChar(QChar::Space), qMax(column, (quint16)2) - 2); - function += QStringLiteral("(function ") + handlerName + QLatin1Char('('); + function += QLatin1String("(function ") + handlerName + QLatin1Char('('); if (parameterString.isEmpty()) { QString error; @@ -97,7 +97,7 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, } else function += parameterString; - function += QStringLiteral(") { ") + expression + QStringLiteral(" })"); + function += QLatin1String(") { ") + expression + QLatin1String(" })"); m_function.set(v4, evalFunction(context(), scopeObject(), function, fileName, line)); if (m_function.isNullOrUndefined()) diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index f7191feec5..d391f38b61 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1669,7 +1669,7 @@ void QQmlData::destroyed(QObject *object) QString source = expr->expression(); if (source.size() > 100) { source.truncate(96); - source.append(QStringLiteral(" ...")); + source.append(QLatin1String(" ...")); } locationString.append(source); } else { diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 01f1042de4..9393f74a8d 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -913,7 +913,7 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector &res // To avoid traversing all static plugins for all imports, we cut down // the list the first time called to only contain QML plugins: foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) { - if (plugin.metaData().value(QStringLiteral("IID")).toString() == QLatin1String(QQmlExtensionInterface_iid)) + if (plugin.metaData().value(QLatin1String("IID")).toString() == QLatin1String(QQmlExtensionInterface_iid)) plugins.append(plugin); } } @@ -921,7 +921,7 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector &res foreach (const QStaticPlugin &plugin, plugins) { // Since a module can list more than one plugin, we keep iterating even after we found a match. if (QQmlExtensionPlugin *instance = qobject_cast(plugin.instance())) { - const QJsonArray metaTagsUriList = plugin.metaData().value(QStringLiteral("uri")).toArray(); + const QJsonArray metaTagsUriList = plugin.metaData().value(QLatin1String("uri")).toArray(); if (metaTagsUriList.isEmpty()) { if (errors) { QQmlError error; @@ -1817,7 +1817,7 @@ void QQmlImportDatabase::addImportPath(const QString& path) } else if (path.startsWith(QLatin1Char(':'))) { // qrc directory, e.g. :/foo // need to convert to a qrc url, e.g. qrc:/foo - cPath = QStringLiteral("qrc") + path; + cPath = QLatin1String("qrc") + path; cPath.replace(Backslash, Slash); } else if (url.isRelative() || (url.scheme().length() == 1 && QFile::exists(path)) ) { // windows path diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 562e7d1746..313eec8f69 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -622,7 +622,7 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, setNamedProperty(methodName, ii, data, (old != 0)); if (data->isSignal()) { - QHashedString on(QStringLiteral("on") % methodName.at(0).toUpper() % methodName.midRef(1)); + QHashedString on(QLatin1String("on") % methodName.at(0).toUpper() % methodName.midRef(1)); setNamedProperty(on, ii, sigdata, (old != 0)); ++signalHandlerIndex; } diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 9a1d9e50d1..d6d4553946 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1654,7 +1654,7 @@ void QQmlDelegateModelItemMetaType::initializeMetaObject() int notifierId = 0; for (int i = 0; i < groupNames.count(); ++i, ++notifierId) { - QString propertyName = QStringLiteral("in") + groupNames.at(i); + QString propertyName = QLatin1String("in") + groupNames.at(i); propertyName.replace(2, 1, propertyName.at(2).toUpper()); builder.addSignal("__" + propertyName.toUtf8() + "Changed()"); QMetaPropertyBuilder propertyBuilder = builder.addProperty( @@ -1662,7 +1662,7 @@ void QQmlDelegateModelItemMetaType::initializeMetaObject() propertyBuilder.setWritable(true); } for (int i = 0; i < groupNames.count(); ++i, ++notifierId) { - const QString propertyName = groupNames.at(i) + QStringLiteral("Index"); + const QString propertyName = groupNames.at(i) + QLatin1String("Index"); builder.addSignal("__" + propertyName.toUtf8() + "Changed()"); QMetaPropertyBuilder propertyBuilder = builder.addProperty( propertyName.toUtf8(), "int", notifierId); @@ -1710,7 +1710,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype() proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); for (int i = 2; i < groupNames.count(); ++i) { - QString propertyName = QStringLiteral("in") + groupNames.at(i); + QString propertyName = QLatin1String("in") + groupNames.at(i); propertyName.replace(2, 1, propertyName.at(2).toUpper()); s = v4->newString(propertyName); p->setGetter((f = QV4::DelegateModelGroupFunction::create(global, i + 1, QQmlDelegateModelItem::get_member))); @@ -1718,7 +1718,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype() proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); } for (int i = 2; i < groupNames.count(); ++i) { - const QString propertyName = groupNames.at(i) + QStringLiteral("Index"); + const QString propertyName = groupNames.at(i) + QLatin1String("Index"); s = v4->newString(propertyName); p->setGetter((f = QV4::DelegateModelGroupFunction::create(global, i + 1, QQmlDelegateModelItem::get_index))); p->setSetter(0); -- cgit v1.2.3