diff options
Diffstat (limited to 'src/qml')
44 files changed, 229 insertions, 230 deletions
diff --git a/src/qml/common/qqmljsmemorypool_p.h b/src/qml/common/qqmljsmemorypool_p.h index 0cf7ea84e6..dcf3fafb67 100644 --- a/src/qml/common/qqmljsmemorypool_p.h +++ b/src/qml/common/qqmljsmemorypool_p.h @@ -105,9 +105,9 @@ public: template <typename Tp, typename... Ta> Tp *New(Ta... args) { return new (this->allocate(sizeof(Tp))) Tp(args...); } - QStringRef newString(const QString &string) { + QStringView newString(const QString &string) { strings.append(new QString(string)); - return QStringRef(strings.last()); + return QStringView(*strings.last()); } private: diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index bc979a81e0..8ea97ab956 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -407,7 +407,7 @@ void ScriptDirectivesCollector::importModule(const QString &uri, const QString & QV4::CompiledData::Import *import = engine->pool()->New<QV4::CompiledData::Import>(); import->type = QV4::CompiledData::Import::ImportLibrary; import->uriIndex = jsGenerator->registerString(uri); - import->version = IRBuilder::extractVersion(QStringRef(&version)); + import->version = IRBuilder::extractVersion(QStringView(version)); import->qualifierIndex = jsGenerator->registerString(module); import->location.line = lineNumber; import->location.column = column; @@ -526,7 +526,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiObjectDefinition *node) QQmlJS::AST::UiQualifiedId *lastId = node->qualifiedTypeNameId; while (lastId->next) lastId = lastId->next; - bool isType = lastId->name.unicode()->isUpper(); + bool isType = lastId->name.data()->isUpper(); if (isType) { int idx = 0; if (!defineQMLObject(&idx, node)) @@ -915,7 +915,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) if (memberType == QLatin1String("alias")) { return appendAlias(node); } else { - const QStringRef &name = node->name; + const QStringView &name = node->name; Property *property = New<Property>(); property->isReadOnly = node->isReadonlyMember; @@ -927,7 +927,7 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) property->setBuiltinType(builtinPropertyType); if (!typeFound && memberType.at(0).isUpper()) { - const QStringRef &typeModifier = node->typeModifier; + const QStringView &typeModifier = node->typeModifier; property->setCustomType(registerString(memberType)); if (typeModifier == QLatin1String("list")) { @@ -1043,15 +1043,15 @@ QString IRBuilder::asString(QQmlJS::AST::UiQualifiedId *node) return s; } -QStringRef IRBuilder::asStringRef(QQmlJS::AST::Node *node) +QStringView IRBuilder::asStringRef(QQmlJS::AST::Node *node) { if (!node) - return QStringRef(); + return QStringView(); return textRefAt(node->firstSourceLocation(), node->lastSourceLocation()); } -QTypeRevision IRBuilder::extractVersion(const QStringRef &string) +QTypeRevision IRBuilder::extractVersion(QStringView string) { if (string.isEmpty()) return QTypeRevision(); @@ -1062,9 +1062,9 @@ QTypeRevision IRBuilder::extractVersion(const QStringRef &string) : QTypeRevision::fromVersion(string.left(dot).toInt(), string.mid(dot + 1).toInt()); } -QStringRef IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const +QStringView IRBuilder::textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const { - return QStringRef(&sourceCode, first.offset, last.offset + last.length - first.offset); + return QStringView(sourceCode).mid(first.offset, last.offset + last.length - first.offset); } void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement, QQmlJS::AST::Node *parentNode) @@ -1127,7 +1127,7 @@ void IRBuilder::setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST } } -void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding) +void IRBuilder::tryGeneratingTranslationBinding(QStringView base, AST::ArgumentList *args, QV4::CompiledData::Binding *binding) { if (base == QLatin1String("qsTr")) { QV4::CompiledData::TranslationData translationData; @@ -1138,7 +1138,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no arguments, stop - QStringRef translation; + QStringView translation; if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) { translation = arg1->value; } else { @@ -1179,7 +1179,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no arguments, stop - QStringRef id; + QStringView id; if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) { id = arg1->value; } else { @@ -1207,7 +1207,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no arguments, stop - QStringRef str; + QStringView str; if (QQmlJS::AST::StringLiteral *arg1 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) { str = arg1->value; } else { @@ -1228,7 +1228,7 @@ void IRBuilder::tryGeneratingTranslationBinding(const QStringRef &base, AST::Arg if (!args || !args->expression) return; // no second arguments, stop - QStringRef str; + QStringView str; if (QQmlJS::AST::StringLiteral *arg2 = QQmlJS::AST::cast<QQmlJS::AST::StringLiteral *>(args->expression)) { str = arg2->value; } else { @@ -1408,7 +1408,7 @@ Object *IRBuilder::bindingsTarget() const bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Statement *value) { QQmlJS::SourceLocation loc = value->firstSourceLocation(); - QStringRef str; + QStringView str; QQmlJS::AST::Node *node = value; if (QQmlJS::AST::ExpressionStatement *stmt = QQmlJS::AST::cast<QQmlJS::AST::ExpressionStatement *>(node)) { @@ -1433,7 +1433,7 @@ bool IRBuilder::setId(const QQmlJS::SourceLocation &idLocation, QQmlJS::AST::Sta if (!ch.isLetter() && ch != u) COMPILE_EXCEPTION(loc, tr( "IDs must start with a letter or underscore")); - for (int ii = 1; ii < str.count(); ++ii) { + for (int ii = 1; ii < str.size(); ++ii) { ch = str.at(ii); if (!ch.isLetterOrNumber() && ch != u) COMPILE_EXCEPTION(loc, tr( "IDs must contain only letters, numbers, and underscores")); @@ -1469,7 +1469,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O qualifiedIdElement = qualifiedIdElement->next; currentName += QLatin1Char('.') + qualifiedIdElement->name; - if (!qualifiedIdElement->name.unicode()->isUpper()) + if (!qualifiedIdElement->name.data()->isUpper()) COMPILE_EXCEPTION(qualifiedIdElement->firstSourceLocation(), tr("Expected type name")); break; @@ -1479,7 +1479,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O *object = _object; while (qualifiedIdElement->next) { const quint32 propertyNameIndex = registerString(currentName); - const bool isAttachedProperty = qualifiedIdElement->name.unicode()->isUpper(); + const bool isAttachedProperty = qualifiedIdElement->name.data()->isUpper(); Binding *binding = (*object)->findBinding(propertyNameIndex); if (binding) { diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 254d21001b..7e6c8c1272 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -497,16 +497,16 @@ public: { return defineQMLObject(objectIndex, node->qualifiedTypeNameId, node->qualifiedTypeNameId->firstSourceLocation(), node->initializer, declarationsOverride); } static QString asString(QQmlJS::AST::UiQualifiedId *node); - QStringRef asStringRef(QQmlJS::AST::Node *node); - static QTypeRevision extractVersion(const QStringRef &string); - QStringRef textRefAt(const QQmlJS::SourceLocation &loc) const - { return QStringRef(&sourceCode, loc.offset, loc.length); } - QStringRef textRefAt(const QQmlJS::SourceLocation &first, + QStringView asStringRef(QQmlJS::AST::Node *node); + static QTypeRevision extractVersion(QStringView string); + QStringView textRefAt(const QQmlJS::SourceLocation &loc) const + { return QStringView(sourceCode).mid(loc.offset, loc.length); } + QStringView textRefAt(const QQmlJS::SourceLocation &first, const QQmlJS::SourceLocation &last) const; void setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement, QQmlJS::AST::Node *parentNode); - void tryGeneratingTranslationBinding(const QStringRef &base, QQmlJS::AST::ArgumentList *args, QV4::CompiledData::Binding *binding); + void tryGeneratingTranslationBinding(QStringView base, QQmlJS::AST::ArgumentList *args, QV4::CompiledData::Binding *binding); void appendBinding(QQmlJS::AST::UiQualifiedId *name, QQmlJS::AST::Statement *value, QQmlJS::AST::Node *parentNode); diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 4588690307..f642797761 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3969,14 +3969,14 @@ public: } private: - void collectIdentifiers(QVector<QStringView> &ids, AST::Node *node) { + void collectIdentifiers(QList<QStringView> &ids, AST::Node *node) { class Collector: public QQmlJS::AST::Visitor { private: - QVector<QStringView> &ids; + QList<QStringView> &ids; VolatileMemoryLocationScanner *parent; public: - Collector(QVector<QStringView> &ids, VolatileMemoryLocationScanner *parent) : + Collector(QList<QStringView> &ids, VolatileMemoryLocationScanner *parent) : QQmlJS::AST::Visitor(parent->recursionDepth()), ids(ids), parent(parent) {} diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index 255698d790..e7d7a21294 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -105,15 +105,15 @@ public: class VolatileMemoryLocations { friend VolatileMemoryLocationScanner; bool allVolatile = false; - QVector<QStringView> specificLocations; + QList<QStringView> specificLocations; public: - bool isVolatile(const QStringView &name) { + bool isVolatile(QStringView name) { if (allVolatile) return true; return specificLocations.contains(name); } - void add(const QStringRef &name) { if (!allVolatile) specificLocations.append(name); } + void add(QStringView name) { if (!allVolatile) specificLocations.append(name); } void setAllVolatile() { allVolatile = true; } }; class RValue { diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index a1ddee8234..4c8f0d0658 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -115,7 +115,7 @@ void ScanFunctions::checkDirectivePrologue(StatementList *ast) // allowed. if (strLit->literalToken.length < 2) continue; - QStringRef str = _sourceCode.midRef(strLit->literalToken.offset + 1, strLit->literalToken.length - 2); + QStringView str = QStringView{_sourceCode}.mid(strLit->literalToken.offset + 1, strLit->literalToken.length - 2); if (str == QLatin1String("use strict")) { _context->isStrict = true; } else { @@ -129,7 +129,7 @@ void ScanFunctions::checkDirectivePrologue(StatementList *ast) } } -void ScanFunctions::checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc) +void ScanFunctions::checkName(QStringView name, const QQmlJS::SourceLocation &loc) { if (_context->isStrict) { if (name == QLatin1String("implements") @@ -337,7 +337,7 @@ bool ScanFunctions::visit(PatternElement *ast) for (const auto &name : qAsConst(names)) { if (_context->isStrict && (name.id == QLatin1String("eval") || name.id == QLatin1String("arguments"))) _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Variable name may not be eval or arguments in strict mode")); - checkName(QStringRef(&name.id), ast->identifierToken); + checkName(QStringView(name.id), ast->identifierToken); if (name.id == QLatin1String("arguments")) _context->usesArgumentsObject = Context::ArgumentsObjectNotUsed; if (ast->scope == VariableScope::Const && !ast->initializer && !ast->isForDeclaration && !ast->destructuringPattern()) { @@ -376,7 +376,7 @@ bool ScanFunctions::visit(ExpressionStatement *ast) return false; } else { SourceLocation firstToken = ast->firstSourceLocation(); - if (_sourceCode.midRef(firstToken.offset, firstToken.length) == QLatin1String("function")) { + if (QStringView{_sourceCode}.mid(firstToken.offset, firstToken.length) == QLatin1String("function")) { _cg->throwSyntaxError(firstToken, QStringLiteral("unexpected token")); } } diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h index e39aa2454e..0336398cac 100644 --- a/src/qml/compiler/qv4compilerscanfunctions_p.h +++ b/src/qml/compiler/qv4compilerscanfunctions_p.h @@ -97,7 +97,7 @@ protected: void checkDirectivePrologue(QQmlJS::AST::StatementList *ast); - void checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc); + void checkName(QStringView name, const QQmlJS::SourceLocation &loc); bool visit(QQmlJS::AST::Program *ast) override; void endVisit(QQmlJS::AST::Program *) override; diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index 4b0fe0f5f6..0535e5029f 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -839,8 +839,8 @@ QString ExecutableCompilationUnit::bindingValueAsString(const CompiledData::Bind // This code must match that in the qsTr() implementation const QString &path = fileName(); int lastSlash = path.lastIndexOf(QLatin1Char('/')); - QStringRef context = (lastSlash > -1) ? path.midRef(lastSlash + 1, path.length() - lastSlash - 5) - : QStringRef(); + QStringView context = (lastSlash > -1) ? QStringView{path}.mid(lastSlash + 1, path.length() - lastSlash - 5) + : QStringView(); QByteArray contextUtf8 = context.toUtf8(); QByteArray comment = stringAt(translation.commentIndex).toUtf8(); QByteArray text = stringAt(translation.stringIndex).toUtf8(); diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index cdb3b8942b..3f0a316af7 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -198,7 +198,7 @@ Heap::FunctionObject *FunctionObject::createBuiltinFunction(ExecutionEngine *eng Scope scope(engine); ScopedString name(scope, nameOrSymbol); if (!name) - name = engine->newString(QChar::fromLatin1('[') + nameOrSymbol->toQString().midRef(1) + QChar::fromLatin1(']')); + name = engine->newString(QChar::fromLatin1('[') + QStringView{nameOrSymbol->toQString()}.mid(1) + QChar::fromLatin1(']')); ScopedFunctionObject function(scope, engine->memoryManager->allocate<FunctionObject>(engine->rootContext(), name, code)); function->defineReadonlyConfigurableProperty(engine->id_length(), Value::fromInt32(argumentCount)); diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index 7fa32da8aa..5295bb7232 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -304,7 +304,7 @@ static QString decode(const QString &input, DecodeMode decodeMode, bool *ok) ++r; } if (*r) - output.append(input.midRef(start, i - start + 1)); + output.append(QStringView{input}.mid(start, i - start + 1)); else output.append(QChar(b)); } else { diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 11e2efb64c..bc145f958d 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -177,7 +177,7 @@ void Object::defineAccessorProperty(StringOrSymbol *name, VTable::Call getter, V ScopedProperty p(scope); QString n = name->toQString(); if (n.at(0) == QLatin1Char('@')) - n = QChar::fromLatin1('[') + n.midRef(1) + QChar::fromLatin1(']'); + n = QChar::fromLatin1('[') + QStringView{n}.mid(1) + QChar::fromLatin1(']'); if (getter) { ScopedString getName(scope, v4->newString(QString::fromLatin1("get ") + n)); p->setGetter(ScopedFunctionObject(scope, FunctionObject::createBuiltinFunction(v4, getName, getter, 0))); diff --git a/src/qml/jsruntime/qv4propertykey.cpp b/src/qml/jsruntime/qv4propertykey.cpp index 064d030b83..2479a6cc65 100644 --- a/src/qml/jsruntime/qv4propertykey.cpp +++ b/src/qml/jsruntime/qv4propertykey.cpp @@ -103,7 +103,7 @@ QV4::Heap::String *QV4::PropertyKey::asFunctionName(ExecutionEngine *engine, Fun if (s->internalClass->vtable->isString) n += s->toQString(); else if (str.length() > 1) - n += QChar::fromLatin1('[') + str.midRef(1) + QChar::fromLatin1(']'); + n += QChar::fromLatin1('[') + QStringView{str}.mid(1) + QChar::fromLatin1(']'); } return engine->newString(n); } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index c2171d7c0e..16b9295ab7 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -726,12 +726,12 @@ ReturnedValue RegExpPrototype::method_replace(const FunctionObject *f, const Val if (scope.hasException()) return Encode::undefined(); if (position >= nextSourcePosition) { - accumulatedResult += s->toQString().midRef(nextSourcePosition, position - nextSourcePosition) + replacement; + accumulatedResult += QStringView{s->toQString()}.mid(nextSourcePosition, position - nextSourcePosition) + replacement; nextSourcePosition = position + matchLength; } } if (nextSourcePosition < lengthS) { - accumulatedResult += s->toQString().midRef(nextSourcePosition); + accumulatedResult += QStringView{s->toQString()}.mid(nextSourcePosition); } return scope.engine->newString(accumulatedResult)->asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 5fc94b9ddd..393f99dd8f 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -417,7 +417,7 @@ double RuntimeHelpers::stringToNumber(const QString &string) if (string.length() > excessiveLength) return qQNaN(); - const QStringRef s = QStringRef(&string).trimmed(); + const QStringView s = QStringView(string).trimmed(); if (s.startsWith(QLatin1Char('0'))) { int base = -1; if (s.startsWith(QLatin1String("0x")) || s.startsWith(QLatin1String("0X"))) diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index 7fa3544e5a..10250f6adc 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -96,7 +96,7 @@ void Script::parse() if (sourceCode.startsWith(QLatin1String("function("))) { static const int snippetLength = 70; qWarning() << "Warning: Using function expressions as statements in scripts is not compliant with the ECMAScript specification:\n" - << (sourceCode.leftRef(snippetLength) + QLatin1String("...")) + << (QStringView{sourceCode}.left(snippetLength) + QLatin1String("...")) << "\nThis will throw a syntax error in Qt 5.12. If you want a function expression, surround it by parentheses."; } diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index bf098fef26..97a8941fe1 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -464,7 +464,7 @@ ReturnedValue StringPrototype::method_endsWith(const FunctionObject *b, const Va if (pos == value.length()) RETURN_RESULT(Encode(value.endsWith(searchString))); - QStringRef stringToSearch = value.leftRef(pos); + QStringView stringToSearch = QStringView{value}.left(pos); return Encode(stringToSearch.endsWith(searchString)); } @@ -514,7 +514,7 @@ ReturnedValue StringPrototype::method_includes(const FunctionObject *b, const Va if (pos == 0) RETURN_RESULT(Encode(value.contains(searchString))); - QStringRef stringToSearch = value.midRef(pos); + QStringView stringToSearch = QStringView{value}.mid(pos); return Encode(stringToSearch.contains(searchString)); } @@ -765,7 +765,7 @@ static void appendReplacementString(QString *result, const QString &input, const } i += skip; if (substStart != JSC::Yarr::offsetNoMatch && substEnd != JSC::Yarr::offsetNoMatch) - *result += input.midRef(substStart, substEnd - substStart); + *result += QStringView{input}.mid(substStart, substEnd - substStart); else if (skip == 0) // invalid capture reference. Taken as literal value *result += replaceValue.at(i); } else { @@ -863,11 +863,11 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val Value that = Value::undefinedValue(); replacement = searchCallback->call(&that, arguments, numCaptures + 2); CHECK_EXCEPTION(); - result += string.midRef(lastEnd, matchStart - lastEnd); + result += QStringView{string}.mid(lastEnd, matchStart - lastEnd); result += replacement->toQString(); lastEnd = matchEnd; } - result += string.midRef(lastEnd); + result += QStringView{string}.mid(lastEnd); } else { QString newString = replaceValue->toQString(); result.reserve(string.length() + numStringMatches*newString.size()); @@ -880,11 +880,11 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val if (matchStart == JSC::Yarr::offsetNoMatch) continue; - result += string.midRef(lastEnd, matchStart - lastEnd); + result += QStringView{string}.mid(lastEnd, matchStart - lastEnd); appendReplacementString(&result, string, newString, matchOffsets + baseIndex, numCaptures); lastEnd = matchEnd; } - result += string.midRef(lastEnd); + result += QStringView{string}.mid(lastEnd); } if (matchOffsets != _matchOffsets) @@ -1052,7 +1052,7 @@ ReturnedValue StringPrototype::method_startsWith(const FunctionObject *b, const if (pos == 0) return Encode(value.startsWith(searchString)); - QStringRef stringToSearch = value.midRef(pos); + QStringView stringToSearch = QStringView{value}.mid(pos); RETURN_RESULT(Encode(stringToSearch.startsWith(searchString))); } diff --git a/src/qml/jsruntime/qv4symbol.cpp b/src/qml/jsruntime/qv4symbol.cpp index be6d821c14..ec25b07fba 100644 --- a/src/qml/jsruntime/qv4symbol.cpp +++ b/src/qml/jsruntime/qv4symbol.cpp @@ -182,5 +182,5 @@ Heap::Symbol *Symbol::create(ExecutionEngine *e, const QString &s) QString Symbol::descriptiveString() const { - return QLatin1String("Symbol(") + toQString().midRef(1) + QLatin1String(")"); + return QLatin1String("Symbol(") + QStringView{toQString()}.mid(1) + QLatin1String(")"); } diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g index 8d79e48287..783ac273c8 100644 --- a/src/qml/parser/qqmljs.g +++ b/src/qml/parser/qqmljs.g @@ -403,10 +403,10 @@ protected: inline Value &sym(int index) { return sym_stack [tos + index - 1]; } - inline QStringRef &stringRef(int index) + inline QStringView &stringRef(int index) { return string_stack [tos + index - 1]; } - inline QStringRef &rawStringRef(int index) + inline QStringView &rawStringRef(int index) { return rawString_stack [tos + index - 1]; } inline SourceLocation &loc(int index) @@ -444,8 +444,8 @@ protected: Value *sym_stack = nullptr; int *state_stack = nullptr; SourceLocation *location_stack = nullptr; - QVector<QStringRef> string_stack; - QVector<QStringRef> rawString_stack; + QList<QStringView> string_stack; + QList<QStringView> rawString_stack; AST::Node *program = nullptr; @@ -456,14 +456,14 @@ protected: int token; double dval; SourceLocation loc; - QStringRef spell; - QStringRef raw; + QStringView spell; + QStringView raw; }; int yytoken = -1; double yylval = 0.; - QStringRef yytokenspell; - QStringRef yytokenraw; + QStringView yytokenspell; + QStringView yytokenraw; SourceLocation yylloc; SourceLocation yyprevlloc; @@ -555,7 +555,7 @@ static inline SourceLocation location(Lexer *lexer) AST::UiQualifiedId *Parser::reparseAsQualifiedId(AST::ExpressionNode *expr) { - QVarLengthArray<QStringRef, 4> nameIds; + QVarLengthArray<QStringView, 4> nameIds; QVarLengthArray<SourceLocation, 4> locations; AST::ExpressionNode *it = expr; @@ -3613,7 +3613,7 @@ ContinueStatement: T_CONTINUE IdentifierReference Semicolon; BreakStatement: T_BREAK Semicolon; /. case $rule_number: { - AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringRef()); + AST::BreakStatement *node = new (pool) AST::BreakStatement(QStringView()); node->breakToken = loc(1); node->semicolonToken = loc(2); sym(1).Node = node; @@ -3887,7 +3887,7 @@ FunctionDeclaration_Default: Function T_LPAREN FormalParameters T_RPAREN TypeAnn case $rule_number: { if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList)) return false; - AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList, + AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(7).StatementList, /*type annotation*/nullptr); node->functionToken = loc(1); node->lparenToken = loc(2); @@ -3921,7 +3921,7 @@ FunctionExpression: T_FUNCTION T_LPAREN FormalParameters T_RPAREN TypeAnnotation case $rule_number: { if (!ensureNoFunctionTypeAnnotations(sym(5).TypeAnnotation, sym(3).FormalParameterList)) return false; - AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(7).StatementList, + AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(7).StatementList, /*type annotation*/nullptr); node->functionToken = loc(1); node->lparenToken = loc(2); @@ -4011,7 +4011,7 @@ ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead AssignmentExpress ret->returnToken = sym(4).Node->firstSourceLocation(); ret->semicolonToken = sym(4).Node->lastSourceLocation(); AST::StatementList *statements = (new (pool) AST::StatementList(ret))->finish(); - AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, statements); + AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, statements); f->isArrowFunction = true; f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1); f->lbraceToken = sym(4).Node->firstSourceLocation(); @@ -4025,7 +4025,7 @@ ArrowFunction: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK Functi ArrowFunction_In: ArrowParameters T_ARROW ConciseBodyLookahead T_FORCE_BLOCK FunctionLBrace FunctionBody FunctionRBrace; /. case $rule_number: { - AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringRef(), sym(1).FormalParameterList, sym(6).StatementList); + AST::FunctionExpression *f = new (pool) AST::FunctionExpression(QStringView(), sym(1).FormalParameterList, sym(6).StatementList); f->isArrowFunction = true; f->functionToken = sym(1).Node ? sym(1).Node->firstSourceLocation() : loc(1); f->lbraceToken = loc(6); @@ -4186,7 +4186,7 @@ GeneratorDeclaration_Default: GeneratorDeclaration; GeneratorDeclaration_Default: FunctionStar GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace; /. case $rule_number: { - AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList); + AST::FunctionDeclaration *node = new (pool) AST::FunctionDeclaration(QStringView(), sym(3).FormalParameterList, sym(6).StatementList); node->functionToken = loc(1); node->lparenToken = loc(2); node->rparenToken = loc(4); @@ -4216,7 +4216,7 @@ GeneratorExpression: T_FUNCTION_STAR BindingIdentifier GeneratorLParen FormalPar GeneratorExpression: T_FUNCTION_STAR GeneratorLParen FormalParameters T_RPAREN FunctionLBrace GeneratorBody GeneratorRBrace; /. case $rule_number: { - AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringRef(), sym(3).FormalParameterList, sym(6).StatementList); + AST::FunctionExpression *node = new (pool) AST::FunctionExpression(QStringView(), sym(3).FormalParameterList, sym(6).StatementList); node->functionToken = loc(1); node->lparenToken = loc(2); node->rparenToken = loc(4); @@ -4291,7 +4291,7 @@ ClassExpression: T_CLASS BindingIdentifier ClassHeritageOpt ClassLBrace ClassBod ClassDeclaration_Default: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt ClassRBrace; /. case $rule_number: { - AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringRef(), sym(2).Expression, sym(4).ClassElementList); + AST::ClassDeclaration *node = new (pool) AST::ClassDeclaration(QStringView(), sym(2).Expression, sym(4).ClassElementList); node->classToken = loc(1); node->lbraceToken = loc(3); node->rbraceToken = loc(5); @@ -4302,7 +4302,7 @@ ClassDeclaration_Default: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt Clas ClassExpression: T_CLASS ClassHeritageOpt ClassLBrace ClassBodyOpt ClassRBrace; /. case $rule_number: { - AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringRef(), sym(2).Expression, sym(4).ClassElementList); + AST::ClassExpression *node = new (pool) AST::ClassExpression(QStringView(), sym(2).Expression, sym(4).ClassElementList); node->classToken = loc(1); node->lbraceToken = loc(3); node->rbraceToken = loc(5); diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h index 700643e1df..f846a5a3dc 100644 --- a/src/qml/parser/qqmljsast_p.h +++ b/src/qml/parser/qqmljsast_p.h @@ -335,11 +335,11 @@ class QML_PARSER_EXPORT UiQualifiedId: public Node public: QQMLJS_DECLARE_AST_NODE(UiQualifiedId) - UiQualifiedId(const QStringRef &name) + UiQualifiedId(QStringView name) : next(this), name(name) { kind = K; } - UiQualifiedId(UiQualifiedId *previous, const QStringRef &name) + UiQualifiedId(UiQualifiedId *previous, QStringView name) : name(name) { kind = K; @@ -364,7 +364,7 @@ public: // attributes UiQualifiedId *next; - QStringRef name; + QStringView name; SourceLocation identifierToken; }; @@ -549,7 +549,7 @@ class QML_PARSER_EXPORT IdentifierExpression: public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(IdentifierExpression) - IdentifierExpression(const QStringRef &n): + IdentifierExpression(QStringView n): name (n) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -561,7 +561,7 @@ public: { return identifierToken; } // attributes - QStringRef name; + QStringView name; SourceLocation identifierToken; }; @@ -698,7 +698,7 @@ class QML_PARSER_EXPORT StringLiteral : public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(StringLiteral) - StringLiteral(const QStringRef &v): + StringLiteral(QStringView v): value (v) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -710,7 +710,7 @@ public: { return literalToken; } // attributes: - QStringRef value; + QStringView value; SourceLocation literalToken; }; @@ -719,7 +719,7 @@ class QML_PARSER_EXPORT TemplateLiteral : public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(TemplateLiteral) - TemplateLiteral(const QStringRef &str, const QStringRef &raw, ExpressionNode *e) + TemplateLiteral(QStringView str, QStringView raw, ExpressionNode *e) : value(str), rawValue(raw), expression(e), next(nullptr) { kind = K; } @@ -734,8 +734,8 @@ public: void accept0(BaseVisitor *visitor) override; - QStringRef value; - QStringRef rawValue; + QStringView value; + QStringView rawValue; ExpressionNode *expression; TemplateLiteral *next; SourceLocation literalToken; @@ -746,7 +746,7 @@ class QML_PARSER_EXPORT RegExpLiteral: public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(RegExpLiteral) - RegExpLiteral(const QStringRef &p, int f): + RegExpLiteral(QStringView p, int f): pattern (p), flags (f) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -758,7 +758,7 @@ public: { return literalToken; } // attributes: - QStringRef pattern; + QStringView pattern; int flags; SourceLocation literalToken; }; @@ -937,7 +937,7 @@ public: : initializer(i), type(t) { kind = K; } - PatternElement(const QStringRef &n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding) + PatternElement(QStringView n, TypeAnnotation *typeAnnotation = nullptr, ExpressionNode *i = nullptr, Type t = Binding) : bindingIdentifier(n), initializer(i), type(t) , typeAnnotation(typeAnnotation) { @@ -973,7 +973,7 @@ public: // attributes SourceLocation identifierToken; - QStringRef bindingIdentifier; + QStringView bindingIdentifier; ExpressionNode *bindingTarget = nullptr; ExpressionNode *initializer = nullptr; Type type = Literal; @@ -1032,7 +1032,7 @@ public: : PatternElement(i, t), name(name) { kind = K; } - PatternProperty(PropertyName *name, const QStringRef &n, ExpressionNode *i = nullptr) + PatternProperty(PropertyName *name, QStringView n, ExpressionNode *i = nullptr) : PatternElement(n, /*type annotation*/nullptr, i), name(name) { kind = K; } @@ -1102,7 +1102,7 @@ class QML_PARSER_EXPORT IdentifierPropertyName: public PropertyName public: QQMLJS_DECLARE_AST_NODE(IdentifierPropertyName) - IdentifierPropertyName(const QStringRef &n): + IdentifierPropertyName(QStringView n): id (n) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -1110,7 +1110,7 @@ public: QString asString() const override { return id.toString(); } // attributes - QStringRef id; + QStringView id; }; class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName @@ -1118,7 +1118,7 @@ class QML_PARSER_EXPORT StringLiteralPropertyName: public PropertyName public: QQMLJS_DECLARE_AST_NODE(StringLiteralPropertyName) - StringLiteralPropertyName(const QStringRef &n): + StringLiteralPropertyName(QStringView n): id (n) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -1126,7 +1126,7 @@ public: QString asString() const override { return id.toString(); } // attributes - QStringRef id; + QStringView id; }; class QML_PARSER_EXPORT NumericLiteralPropertyName: public PropertyName @@ -1198,7 +1198,7 @@ class QML_PARSER_EXPORT FieldMemberExpression: public LeftHandSideExpression public: QQMLJS_DECLARE_AST_NODE(FieldMemberExpression) - FieldMemberExpression(ExpressionNode *b, const QStringRef &n): + FieldMemberExpression(ExpressionNode *b, QStringView n): base (b), name (n) { kind = K; } @@ -1212,7 +1212,7 @@ public: // attributes ExpressionNode *base; - QStringRef name; + QStringView name; SourceLocation dotToken; SourceLocation identifierToken; }; @@ -1988,7 +1988,7 @@ class QML_PARSER_EXPORT ContinueStatement: public Statement public: QQMLJS_DECLARE_AST_NODE(ContinueStatement) - ContinueStatement(const QStringRef &l = QStringRef()): + ContinueStatement(QStringView l = QStringView()): label (l) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -2000,7 +2000,7 @@ public: { return semicolonToken; } // attributes - QStringRef label; + QStringView label; SourceLocation continueToken; SourceLocation identifierToken; SourceLocation semicolonToken; @@ -2011,7 +2011,7 @@ class QML_PARSER_EXPORT BreakStatement: public Statement public: QQMLJS_DECLARE_AST_NODE(BreakStatement) - BreakStatement(const QStringRef &l): + BreakStatement(QStringView l): label (l) { kind = K; } void accept0(BaseVisitor *visitor) override; @@ -2023,7 +2023,7 @@ public: { return semicolonToken; } // attributes - QStringRef label; + QStringView label; SourceLocation breakToken; SourceLocation identifierToken; SourceLocation semicolonToken; @@ -2239,7 +2239,7 @@ class QML_PARSER_EXPORT LabelledStatement: public Statement public: QQMLJS_DECLARE_AST_NODE(LabelledStatement) - LabelledStatement(const QStringRef &l, Statement *stmt): + LabelledStatement(QStringView l, Statement *stmt): label (l), statement (stmt) { kind = K; } @@ -2252,7 +2252,7 @@ public: { return statement->lastSourceLocation(); } // attributes - QStringRef label; + QStringView label; Statement *statement; SourceLocation identifierToken; SourceLocation colonToken; @@ -2372,7 +2372,7 @@ class QML_PARSER_EXPORT FunctionExpression: public ExpressionNode public: QQMLJS_DECLARE_AST_NODE(FunctionExpression) - FunctionExpression(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): + FunctionExpression(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): name (n), formals (f), body (b), typeAnnotation(typeAnnotation) { kind = K; } @@ -2388,7 +2388,7 @@ public: FunctionExpression *asFunctionDefinition() override; // attributes - QStringRef name; + QStringView name; bool isArrowFunction = false; bool isGenerator = false; FormalParameterList *formals; @@ -2407,7 +2407,7 @@ class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression public: QQMLJS_DECLARE_AST_NODE(FunctionDeclaration) - FunctionDeclaration(const QStringRef &n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): + FunctionDeclaration(QStringView n, FormalParameterList *f, StatementList *b, TypeAnnotation *typeAnnotation = nullptr): FunctionExpression(n, f, b, typeAnnotation) { kind = K; } @@ -2504,7 +2504,7 @@ class QML_PARSER_EXPORT ClassExpression : public ExpressionNode public: QQMLJS_DECLARE_AST_NODE(ClassExpression) - ClassExpression(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements) + ClassExpression(QStringView n, ExpressionNode *heritage, ClassElementList *elements) : name(n), heritage(heritage), elements(elements) { kind = K; } @@ -2519,7 +2519,7 @@ public: ClassExpression *asClassDefinition() override; // attributes - QStringRef name; + QStringView name; ExpressionNode *heritage; ClassElementList *elements; SourceLocation classToken; @@ -2533,7 +2533,7 @@ class QML_PARSER_EXPORT ClassDeclaration: public ClassExpression public: QQMLJS_DECLARE_AST_NODE(ClassDeclaration) - ClassDeclaration(const QStringRef &n, ExpressionNode *heritage, ClassElementList *elements) + ClassDeclaration(QStringView n, ExpressionNode *heritage, ClassElementList *elements) : ClassExpression(n, heritage, elements) { kind = K; } @@ -2604,13 +2604,13 @@ class QML_PARSER_EXPORT ImportSpecifier: public Node public: QQMLJS_DECLARE_AST_NODE(ImportSpecifier) - ImportSpecifier(const QStringRef &importedBinding) + ImportSpecifier(QStringView importedBinding) : importedBinding(importedBinding) { kind = K; } - ImportSpecifier(const QStringRef &identifier, const QStringRef &importedBinding) + ImportSpecifier(QStringView identifier, QStringView importedBinding) : identifier(identifier), importedBinding(importedBinding) { kind = K; @@ -2626,8 +2626,8 @@ public: // attributes SourceLocation identifierToken; SourceLocation importedBindingToken; - QStringRef identifier; - QStringRef importedBinding; + QStringView identifier; + QStringView importedBinding; }; class QML_PARSER_EXPORT ImportsList: public Node @@ -2711,7 +2711,7 @@ class QML_PARSER_EXPORT NameSpaceImport: public Node public: QQMLJS_DECLARE_AST_NODE(NameSpaceImport) - NameSpaceImport(const QStringRef &importedBinding) + NameSpaceImport(QStringView importedBinding) : importedBinding(importedBinding) { kind = K; @@ -2727,7 +2727,7 @@ public: // attributes SourceLocation starToken; SourceLocation importedBindingToken; - QStringRef importedBinding; + QStringView importedBinding; }; class QML_PARSER_EXPORT ImportClause: public Node @@ -2735,7 +2735,7 @@ class QML_PARSER_EXPORT ImportClause: public Node public: QQMLJS_DECLARE_AST_NODE(ImportClause) - ImportClause(const QStringRef &importedDefaultBinding) + ImportClause(QStringView importedDefaultBinding) : importedDefaultBinding(importedDefaultBinding) { kind = K; @@ -2753,14 +2753,14 @@ public: kind = K; } - ImportClause(const QStringRef &importedDefaultBinding, NameSpaceImport *nameSpaceImport) + ImportClause(QStringView importedDefaultBinding, NameSpaceImport *nameSpaceImport) : importedDefaultBinding(importedDefaultBinding) , nameSpaceImport(nameSpaceImport) { kind = K; } - ImportClause(const QStringRef &importedDefaultBinding, NamedImports *namedImports) + ImportClause(QStringView importedDefaultBinding, NamedImports *namedImports) : importedDefaultBinding(importedDefaultBinding) , namedImports(namedImports) { @@ -2776,7 +2776,7 @@ public: // attributes SourceLocation importedDefaultBindingToken; - QStringRef importedDefaultBinding; + QStringView importedDefaultBinding; NameSpaceImport *nameSpaceImport = nullptr; NamedImports *namedImports = nullptr; }; @@ -2786,7 +2786,7 @@ class QML_PARSER_EXPORT FromClause: public Node public: QQMLJS_DECLARE_AST_NODE(FromClause) - FromClause(const QStringRef &moduleSpecifier) + FromClause(QStringView moduleSpecifier) : moduleSpecifier(moduleSpecifier) { kind = K; @@ -2803,7 +2803,7 @@ public: // attributes SourceLocation fromToken; SourceLocation moduleSpecifierToken; - QStringRef moduleSpecifier; + QStringView moduleSpecifier; }; class QML_PARSER_EXPORT ImportDeclaration: public Statement @@ -2817,7 +2817,7 @@ public: kind = K; } - ImportDeclaration(const QStringRef &moduleSpecifier) + ImportDeclaration(QStringView moduleSpecifier) : moduleSpecifier(moduleSpecifier) { kind = K; @@ -2834,7 +2834,7 @@ public: // attributes SourceLocation importToken; SourceLocation moduleSpecifierToken; - QStringRef moduleSpecifier; + QStringView moduleSpecifier; ImportClause *importClause = nullptr; FromClause *fromClause = nullptr; }; @@ -2844,13 +2844,13 @@ class QML_PARSER_EXPORT ExportSpecifier: public Node public: QQMLJS_DECLARE_AST_NODE(ExportSpecifier) - ExportSpecifier(const QStringRef &identifier) + ExportSpecifier(QStringView identifier) : identifier(identifier), exportedIdentifier(identifier) { kind = K; } - ExportSpecifier(const QStringRef &identifier, const QStringRef &exportedIdentifier) + ExportSpecifier(QStringView identifier, QStringView exportedIdentifier) : identifier(identifier), exportedIdentifier(exportedIdentifier) { kind = K; @@ -2866,8 +2866,8 @@ public: // attributes SourceLocation identifierToken; SourceLocation exportedIdentifierToken; - QStringRef identifier; - QStringRef exportedIdentifier; + QStringView identifier; + QStringView exportedIdentifier; }; class QML_PARSER_EXPORT ExportsList: public Node @@ -3038,7 +3038,7 @@ class QML_PARSER_EXPORT UiImport: public Node public: QQMLJS_DECLARE_AST_NODE(UiImport) - UiImport(const QStringRef &fileName) + UiImport(QStringView fileName) : fileName(fileName), importUri(nullptr) { kind = K; } @@ -3055,9 +3055,9 @@ public: { return semicolonToken; } // attributes - QStringRef fileName; + QStringView fileName; UiQualifiedId *importUri; - QStringRef importId; + QStringView importId; SourceLocation importToken; SourceLocation fileNameToken; SourceLocation asToken; @@ -3120,7 +3120,7 @@ class QML_PARSER_EXPORT UiPragma: public Node public: QQMLJS_DECLARE_AST_NODE(UiPragma) - UiPragma(QStringRef name) + UiPragma(QStringView name) : name(name) { kind = K; } @@ -3133,7 +3133,7 @@ public: { return semicolonToken; } // attributes - QStringRef name; + QStringView name; SourceLocation pragmaToken; SourceLocation semicolonToken; }; @@ -3143,7 +3143,7 @@ class QML_PARSER_EXPORT UiRequired: public Node public: QQMLJS_DECLARE_AST_NODE(UiRequired) - UiRequired(QStringRef name) + UiRequired(QStringView name) :name(name) { kind = K; } @@ -3155,7 +3155,7 @@ public: SourceLocation lastSourceLocation() const override { return semicolonToken; } - QStringRef name; + QStringView name; SourceLocation requiredToken; SourceLocation semicolonToken; }; @@ -3309,11 +3309,11 @@ class QML_PARSER_EXPORT UiParameterList: public Node public: QQMLJS_DECLARE_AST_NODE(UiParameterList) - UiParameterList(UiQualifiedId *t, const QStringRef &n): + UiParameterList(UiQualifiedId *t, QStringView n): type (t), name (n), next (this) { kind = K; } - UiParameterList(UiParameterList *previous, UiQualifiedId *t, const QStringRef &n): + UiParameterList(UiParameterList *previous, UiQualifiedId *t, QStringView n): type (t), name (n) { kind = K; @@ -3341,7 +3341,7 @@ public: // attributes UiQualifiedId *type; - QStringRef name; + QStringView name; UiParameterList *next; SourceLocation commaToken; SourceLocation propertyTypeToken; @@ -3355,12 +3355,12 @@ public: QQMLJS_DECLARE_AST_NODE(UiPublicMember) UiPublicMember(UiQualifiedId *memberType, - const QStringRef &name) + QStringView name) : type(Property), memberType(memberType), name(name), statement(nullptr), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr) { kind = K; } UiPublicMember(UiQualifiedId *memberType, - const QStringRef &name, + QStringView name, Statement *statement) : type(Property), memberType(memberType), name(name), statement(statement), binding(nullptr), isDefaultMember(false), isReadonlyMember(false), parameters(nullptr) { kind = K; } @@ -3391,9 +3391,9 @@ public: // attributes enum { Signal, Property } type; - QStringRef typeModifier; + QStringView typeModifier; UiQualifiedId *memberType; - QStringRef name; + QStringView name; Statement *statement; // initialized with a JS expression UiObjectMember *binding; // initialized with a QML object or array. bool isDefaultMember; @@ -3440,7 +3440,7 @@ class QML_PARSER_EXPORT UiInlineComponent: public UiObjectMember public: QQMLJS_DECLARE_AST_NODE(UiInlineComponent) - UiInlineComponent(const QStringRef& inlineComponentName, UiObjectDefinition* inlineComponent) + UiInlineComponent(QStringView inlineComponentName, UiObjectDefinition* inlineComponent) : name(inlineComponentName), component(inlineComponent) { kind = K; } @@ -3453,7 +3453,7 @@ public: void accept0(BaseVisitor *visitor) override; // attributes - QStringRef name; + QStringView name; UiObjectDefinition* component; SourceLocation componentToken; }; @@ -3586,11 +3586,11 @@ class QML_PARSER_EXPORT UiEnumMemberList: public Node { QQMLJS_DECLARE_AST_NODE(UiEnumMemberList) public: - UiEnumMemberList(const QStringRef &member, double v = 0.0) + UiEnumMemberList(QStringView member, double v = 0.0) : next(this), member(member), value(v) { kind = K; } - UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member) + UiEnumMemberList(UiEnumMemberList *previous, QStringView member) : member(member) { kind = K; @@ -3599,7 +3599,7 @@ public: value = previous->value + 1; } - UiEnumMemberList(UiEnumMemberList *previous, const QStringRef &member, double v) + UiEnumMemberList(UiEnumMemberList *previous, QStringView member, double v) : member(member), value(v) { kind = K; @@ -3627,7 +3627,7 @@ public: // attributes UiEnumMemberList *next; - QStringRef member; + QStringView member; double value; SourceLocation memberToken; SourceLocation valueToken; @@ -3638,7 +3638,7 @@ class QML_PARSER_EXPORT UiEnumDeclaration: public UiObjectMember public: QQMLJS_DECLARE_AST_NODE(UiEnumDeclaration) - UiEnumDeclaration(const QStringRef &name, + UiEnumDeclaration(QStringView name, UiEnumMemberList *members) : name(name) , members(members) @@ -3655,7 +3655,7 @@ public: // attributes SourceLocation enumToken; SourceLocation rbraceToken; - QStringRef name; + QStringView name; UiEnumMemberList *members; }; diff --git a/src/qml/parser/qqmljsengine_p.cpp b/src/qml/parser/qqmljsengine_p.cpp index cb6b0375e6..53ad8820dd 100644 --- a/src/qml/parser/qqmljsengine_p.cpp +++ b/src/qml/parser/qqmljsengine_p.cpp @@ -143,14 +143,13 @@ void Engine::setDirectives(Directives *directives) MemoryPool *Engine::pool() { return &_pool; } -QStringRef Engine::newStringRef(const QString &text) +QStringView Engine::newStringRef(const QString &text) { - const int pos = _extraCode.length(); - _extraCode += text; - return _extraCode.midRef(pos, text.length()); + _extraCode.append(text); + return QStringView{_extraCode.last()}; } -QStringRef Engine::newStringRef(const QChar *chars, int size) +QStringView Engine::newStringRef(const QChar *chars, int size) { return newStringRef(QString(chars, size)); } } // end of namespace QQmlJS diff --git a/src/qml/parser/qqmljsengine_p.h b/src/qml/parser/qqmljsengine_p.h index a34922fa1e..b57515982b 100644 --- a/src/qml/parser/qqmljsengine_p.h +++ b/src/qml/parser/qqmljsengine_p.h @@ -98,7 +98,7 @@ class QML_PARSER_EXPORT Engine Directives *_directives; MemoryPool _pool; QList<SourceLocation> _comments; - QString _extraCode; + QStringList _extraCode; QString _code; public: @@ -119,10 +119,10 @@ public: MemoryPool *pool(); - inline QStringRef midRef(int position, int size) { return _code.midRef(position, size); } + inline QStringView midRef(int position, int size) { return QStringView{_code}.mid(position, size); } - QStringRef newStringRef(const QString &s); - QStringRef newStringRef(const QChar *chars, int size); + QStringView newStringRef(const QString &s); + QStringView newStringRef(const QChar *chars, int size); }; double integerFromString(const char *buf, int size, int radix); diff --git a/src/qml/parser/qqmljslexer.cpp b/src/qml/parser/qqmljslexer.cpp index cdab17ff63..601596a9e3 100644 --- a/src/qml/parser/qqmljslexer.cpp +++ b/src/qml/parser/qqmljslexer.cpp @@ -132,8 +132,8 @@ void Lexer::setCode(const QString &code, int lineno, bool qmlMode) _tokenText.clear(); _tokenText.reserve(1024); _errorMessage.clear(); - _tokenSpell = QStringRef(); - _rawString = QStringRef(); + _tokenSpell = QStringView(); + _rawString = QStringView(); _codePtr = code.unicode(); _endPtr = _codePtr + code.length(); @@ -256,8 +256,8 @@ int Lexer::lex() const int previousTokenKind = _tokenKind; again: - _tokenSpell = QStringRef(); - _rawString = QStringRef(); + _tokenSpell = QStringView(); + _rawString = QStringView(); _tokenKind = scanToken(); _tokenLength = _codePtr - _tokenStartPtr - 1; diff --git a/src/qml/parser/qqmljslexer_p.h b/src/qml/parser/qqmljslexer_p.h index e2ee4ae351..7b4c219506 100644 --- a/src/qml/parser/qqmljslexer_p.h +++ b/src/qml/parser/qqmljslexer_p.h @@ -165,8 +165,8 @@ public: int tokenStartLine() const { return _tokenLine; } int tokenStartColumn() const { return _tokenColumn; } - inline QStringRef tokenSpell() const { return _tokenSpell; } - inline QStringRef rawString() const { return _rawString; } + inline QStringView tokenSpell() const { return _tokenSpell; } + inline QStringView rawString() const { return _rawString; } double tokenValue() const { return _tokenValue; } QString tokenText() const; @@ -219,8 +219,8 @@ private: QString _code; QString _tokenText; QString _errorMessage; - QStringRef _tokenSpell; - QStringRef _rawString; + QStringView _tokenSpell; + QStringView _rawString; const QChar *_codePtr; const QChar *_endPtr; diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index 08f019b4bd..c5353acdb1 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -100,7 +100,7 @@ class Q_QML_PRIVATE_EXPORT QHashedStringRef public: inline QHashedStringRef(); inline QHashedStringRef(const QString &); - inline QHashedStringRef(const QStringRef &); + inline QHashedStringRef(QStringView); inline QHashedStringRef(const QChar *, int); inline QHashedStringRef(const QChar *, int, quint32); inline QHashedStringRef(const QHashedString &); @@ -242,7 +242,7 @@ QHashedStringRef::QHashedStringRef(const QString &str) { } -QHashedStringRef::QHashedStringRef(const QStringRef &str) +QHashedStringRef::QHashedStringRef(QStringView str) : m_data(str.constData()), m_length(str.length()), m_hash(0) { } diff --git a/src/qml/qml/ftw/qstringhash_p.h b/src/qml/qml/ftw/qstringhash_p.h index b785525ea4..7a2184d63f 100644 --- a/src/qml/qml/ftw/qstringhash_p.h +++ b/src/qml/qml/ftw/qstringhash_p.h @@ -253,7 +253,7 @@ template<typename T> struct HashedForm {}; template<> struct HashedForm<QString> { typedef QHashedString Type; }; -template<> struct HashedForm<QStringRef> { typedef QHashedStringRef Type; }; +template<> struct HashedForm<QStringView> { typedef QHashedStringRef Type; }; template<> struct HashedForm<QHashedString> { typedef const QHashedString &Type; }; template<> struct HashedForm<QV4::String *> { typedef const QV4::String *Type; }; template<> struct HashedForm<const QV4::String *> { typedef const QV4::String *Type; }; @@ -265,7 +265,7 @@ class QStringHashBase { public: static HashedForm<QString>::Type hashedString(const QString &s) { return QHashedString(s);} - static HashedForm<QStringRef>::Type hashedString(const QStringRef &s) { return QHashedStringRef(s.constData(), s.size());} + static HashedForm<QStringView>::Type hashedString(QStringView s) { return QHashedStringRef(s.constData(), s.size());} static HashedForm<QHashedString>::Type hashedString(const QHashedString &s) { return s; } static HashedForm<QV4::String *>::Type hashedString(QV4::String *s) { return s; } static HashedForm<const QV4::String *>::Type hashedString(const QV4::String *s) { return s; } diff --git a/src/qml/qml/qqmlerror.cpp b/src/qml/qml/qqmlerror.cpp index c71c33a059..706cc8601d 100644 --- a/src/qml/qml/qqmlerror.cpp +++ b/src/qml/qml/qqmlerror.cpp @@ -318,10 +318,10 @@ QDebug operator<<(QDebug debug, const QQmlError &error) QByteArray data = f.readAll(); QTextStream stream(data, QIODevice::ReadOnly); const QString code = stream.readAll(); - const auto lines = code.splitRef(QLatin1Char('\n')); + const auto lines = QStringView{code}.split(QLatin1Char('\n')); if (lines.count() >= error.line()) { - const QStringRef &line = lines.at(error.line() - 1); + const QStringView &line = lines.at(error.line() - 1); debug << "\n " << line.toLocal8Bit().constData(); if(error.column() > 0) { diff --git a/src/qml/qml/qqmlfile.cpp b/src/qml/qml/qqmlfile.cpp index 465a342129..4db8981975 100644 --- a/src/qml/qml/qqmlfile.cpp +++ b/src/qml/qml/qqmlfile.cpp @@ -616,13 +616,13 @@ QString QQmlFile::urlToLocalFileOrQrc(const QString& url) { if (url.startsWith(QLatin1String("qrc://"), Qt::CaseInsensitive)) { if (url.length() > 6) - return QLatin1Char(':') + url.midRef(6); + return QLatin1Char(':') + QStringView{url}.mid(6); return QString(); } if (url.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive)) { if (url.length() > 4) - return QLatin1Char(':') + url.midRef(4); + return QLatin1Char(':') + QStringView{url}.mid(4); return QString(); } diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index a5429afd12..ad7cda2145 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -92,7 +92,7 @@ QString resolveLocalUrl(const QString &url, const QString &relative) } else if (relative.at(0) == Slash || !url.contains(Slash)) { return relative; } else { - const QStringRef baseRef = url.leftRef(url.lastIndexOf(Slash) + 1); + const QStringView baseRef = QStringView{url}.left(url.lastIndexOf(Slash) + 1); if (relative == QLatin1String(".")) return baseRef.toString(); @@ -406,7 +406,7 @@ bool excludeBaseUrl(const QString &importUrl, const QString &fileName, const QSt if (baseUrl.startsWith(importUrl)) { - if (fileName == baseUrl.midRef(importUrl.size())) + if (fileName == QStringView{baseUrl}.mid(importUrl.size())) return false; } @@ -1000,17 +1000,17 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS QString u1 = import->url; QString u2 = import2->url; if (base) { - QStringRef b(base); + QStringView b(*base); int dot = b.lastIndexOf(Dot); if (dot >= 0) { b = b.left(dot+1); - QStringRef l = b.left(dot); + QStringView l = b.left(dot); if (u1.startsWith(b)) - u1 = u1.mid(b.count()); + u1 = u1.mid(b.size()); else if (u1 == l) u1 = QQmlImportDatabase::tr("local directory"); if (u2.startsWith(b)) - u2 = u2.mid(b.count()); + u2 = u2.mid(b.size()); else if (u2 == l) u2 = QQmlImportDatabase::tr("local directory"); } @@ -1400,7 +1400,7 @@ QQmlImports::LocalQmldirResult QQmlImportsPrivate::locateLocalQmldir( QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath); if (!absoluteFilePath.isEmpty()) { QString url; - const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1); + const QStringView absolutePath = QStringView{absoluteFilePath}.left(absoluteFilePath.lastIndexOf(Slash) + 1); if (absolutePath.at(0) == Colon) url = QLatin1String("qrc") + absolutePath; else diff --git a/src/qml/qml/qqmlinfo.h b/src/qml/qml/qqmlinfo.h index faa112d4af..a3ceb405b8 100644 --- a/src/qml/qml/qqmlinfo.h +++ b/src/qml/qml/qqmlinfo.h @@ -91,7 +91,7 @@ public: inline QQmlInfo &operator<<(double t) { QDebug::operator<<(t); return *this; } inline QQmlInfo &operator<<(const char* t) { QDebug::operator<<(t); return *this; } inline QQmlInfo &operator<<(const QString & t) { QDebug::operator<<(t.toLocal8Bit().constData()); return *this; } - inline QQmlInfo &operator<<(const QStringRef & t) { return operator<<(t.toString()); } + inline QQmlInfo &operator<<(QStringView t) { return operator<<(t.toString()); } inline QQmlInfo &operator<<(const QLatin1String &t) { QDebug::operator<<(t.latin1()); return *this; } inline QQmlInfo &operator<<(const QByteArray & t) { QDebug::operator<<(t); return *this; } inline QQmlInfo &operator<<(const void * t) { QDebug::operator<<(t); return *this; } diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index 77a1d0d74a..561c336b66 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -1481,7 +1481,7 @@ QString QQmlMetaType::prettyTypeName(const QObject *object) marker = typeName.indexOf(QLatin1String("_QML_")); if (marker != -1) { - typeName = typeName.leftRef(marker) + QLatin1Char('*'); + typeName = QStringView{typeName}.left(marker) + QLatin1Char('*'); type = QQmlMetaType::qmlType(QMetaType::type(typeName.toLatin1())); if (type.isValid()) { QString qmlTypeName = type.qmlTypeName(); diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 9595675ba6..864f97a417 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -262,16 +262,16 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) QQmlRefPointer<QQmlTypeNameCache> typeNameCache = context ? context->imports() : nullptr; QObject *currentObject = obj; - QVector<QStringRef> path; - QStringRef terminal(&name); + QList<QStringView> path; + QStringView terminal(name); if (name.contains(QLatin1Char('.'))) { - path = name.splitRef(QLatin1Char('.')); + path = QStringView{name}.split(QLatin1Char('.')); if (path.isEmpty()) return; // Everything up to the last property must be an "object type" property for (int ii = 0; ii < path.count() - 1; ++ii) { - const QStringRef &pathName = path.at(ii); + const QStringView &pathName = path.at(ii); // Types must begin with an uppercase letter (see checkRegistration() // in qqmlmetatype.cpp for the enforcement of this). @@ -355,7 +355,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) terminal = path.last(); } - if (terminal.count() >= 3 && terminal.at(0) == u'o' && terminal.at(1) == u'n' + if (terminal.size() >= 3 && terminal.at(0) == u'o' && terminal.at(1) == u'n' && (terminal.at(2).isUpper() || terminal.at(2) == u'_')) { QString signalName = terminal.mid(2).toString(); @@ -384,7 +384,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) // Try property if (signalName.endsWith(QLatin1String("Changed"))) { - const QStringRef propName = signalName.midRef(0, signalName.length() - 7); + const QStringView propName = QStringView{signalName}.mid(0, signalName.length() - 7); QQmlPropertyData *d = ddata->propertyCache->property(propName, currentObject, context); while (d && d->isFunction()) d = ddata->propertyCache->overrideData(d); diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 5fef36e0df..5f91b5b94a 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -551,7 +551,7 @@ void QQmlPropertyCache::append(const QMetaObject *metaObject, setNamedProperty(methodName, ii, data, (old != nullptr)); if (data->isSignal()) { - QHashedString on(QLatin1String("on") % methodName.at(0).toUpper() % methodName.midRef(1)); + QHashedString on(QLatin1String("on") % methodName.at(0).toUpper() % QStringView{methodName}.mid(1)); setNamedProperty(on, ii, sigdata, (old != nullptr)); ++signalHandlerIndex; } @@ -991,7 +991,7 @@ static inline const char *qQmlPropertyCacheToString(QLatin1String string) return string.data(); } -static inline QByteArray qQmlPropertyCacheToString(const QStringRef &string) +static inline QByteArray qQmlPropertyCacheToString(QStringView string) { return string.toUtf8(); } @@ -1043,10 +1043,10 @@ QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QV4::String * } QQmlPropertyData * -QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, const QStringRef &name, +QQmlPropertyCache::property(QJSEngine *engine, QObject *obj, QStringView name, const QQmlRefPointer<QQmlContextData> &context, QQmlPropertyData *local) { - return qQmlPropertyCacheProperty<const QStringRef &>(engine, obj, name, context, local); + return qQmlPropertyCacheProperty<const QStringView &>(engine, obj, name, context, local); } QQmlPropertyData * diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index a6517cc3ff..460e6d9a85 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -185,7 +185,7 @@ public: inline QQmlPropertyData *overrideData(QQmlPropertyData *) const; inline bool isAllowedInRevision(QQmlPropertyData *) const; - static QQmlPropertyData *property(QJSEngine *, QObject *, const QStringRef &, + static QQmlPropertyData *property(QJSEngine *, QObject *, QStringView, const QQmlRefPointer<QQmlContextData> &, QQmlPropertyData *); static QQmlPropertyData *property(QJSEngine *, QObject *, const QLatin1String &, const QQmlRefPointer<QQmlContextData> &, QQmlPropertyData *); @@ -196,7 +196,7 @@ public: const QQmlRefPointer<QQmlContextData> &context, QQmlPropertyData *local) { - return property(engine, obj, QStringRef(&name), context, local); + return property(engine, obj, QStringView(name), context, local); } //see QMetaObjectPrivate::originalClone diff --git a/src/qml/qml/qqmlpropertycachecreator.cpp b/src/qml/qml/qqmlpropertycachecreator.cpp index f132fb2d78..777a698231 100644 --- a/src/qml/qml/qqmlpropertycachecreator.cpp +++ b/src/qml/qml/qqmlpropertycachecreator.cpp @@ -82,7 +82,7 @@ QByteArray QQmlPropertyCacheCreatorBase::createClassNameTypeByUrl(const QUrl &ur if (lastSlash <= -1) return QByteArray(); // ### this might not be correct for .ui.qml files - const QStringRef nameBase = path.midRef(lastSlash + 1, path.length() - lastSlash - 5); + const QStringView nameBase = QStringView{path}.mid(lastSlash + 1, path.length() - lastSlash - 5); // Not a reusable type if it doesn't start with a upper case letter. if (nameBase.isEmpty() || !nameBase.at(0).isUpper()) return QByteArray(); diff --git a/src/qml/qml/qqmlstringconverters.cpp b/src/qml/qml/qqmlstringconverters.cpp index e53f90b45b..d1c7d8cdf3 100644 --- a/src/qml/qml/qqmlstringconverters.cpp +++ b/src/qml/qml/qqmlstringconverters.cpp @@ -143,8 +143,8 @@ QPointF QQmlStringConverters::pointFFromString(const QString &s, bool *ok) bool xGood, yGood; int index = s.indexOf(QLatin1Char(',')); - qreal xCoord = s.leftRef(index).toDouble(&xGood); - qreal yCoord = s.midRef(index+1).toDouble(&yGood); + qreal xCoord = QStringView{s}.left(index).toDouble(&xGood); + qreal yCoord = QStringView{s}.mid(index+1).toDouble(&yGood); if (!xGood || !yGood) { if (ok) *ok = false; @@ -167,8 +167,8 @@ QSizeF QQmlStringConverters::sizeFFromString(const QString &s, bool *ok) bool wGood, hGood; int index = s.indexOf(QLatin1Char('x')); - qreal width = s.leftRef(index).toDouble(&wGood); - qreal height = s.midRef(index+1).toDouble(&hGood); + qreal width = QStringView{s}.left(index).toDouble(&wGood); + qreal height = QStringView{s}.mid(index+1).toDouble(&hGood); if (!wGood || !hGood) { if (ok) *ok = false; @@ -191,12 +191,12 @@ QRectF QQmlStringConverters::rectFFromString(const QString &s, bool *ok) bool xGood, yGood, wGood, hGood; int index = s.indexOf(QLatin1Char(',')); - qreal x = s.leftRef(index).toDouble(&xGood); + qreal x = QStringView{s}.left(index).toDouble(&xGood); int index2 = s.indexOf(QLatin1Char(','), index+1); - qreal y = s.midRef(index+1, index2-index-1).toDouble(&yGood); + qreal y = QStringView{s}.mid(index+1, index2-index-1).toDouble(&yGood); index = s.indexOf(QLatin1Char('x'), index2+1); - qreal width = s.midRef(index2+1, index-index2-1).toDouble(&wGood); - qreal height = s.midRef(index+1).toDouble(&hGood); + qreal width = QStringView{s}.mid(index2+1, index-index2-1).toDouble(&wGood); + qreal height = QStringView{s}.mid(index+1).toDouble(&hGood); if (!xGood || !yGood || !wGood || !hGood) { if (ok) *ok = false; diff --git a/src/qml/qml/qqmltype.cpp b/src/qml/qml/qqmltype.cpp index 5ae87c429d..1d343b91cc 100644 --- a/src/qml/qml/qqmltype.cpp +++ b/src/qml/qml/qqmltype.cpp @@ -846,7 +846,7 @@ int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &scope return -1; } -int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &scopedEnumName, const QStringRef &name, bool *ok) const +int QQmlType::scopedEnumValue(QQmlEnginePrivate *engine, QStringView scopedEnumName, QStringView name, bool *ok) const { Q_ASSERT(ok); if (d) { diff --git a/src/qml/qml/qqmltype_p.h b/src/qml/qml/qqmltype_p.h index eb3a773181..929a5d0c81 100644 --- a/src/qml/qml/qqmltype_p.h +++ b/src/qml/qml/qqmltype_p.h @@ -169,7 +169,7 @@ public: int scopedEnumValue(QQmlEnginePrivate *engine, int index, const QV4::String *, bool *ok) const; int scopedEnumValue(QQmlEnginePrivate *engine, int index, const QString &, bool *ok) const; int scopedEnumValue(QQmlEnginePrivate *engine, const QByteArray &, const QByteArray &, bool *ok) const; - int scopedEnumValue(QQmlEnginePrivate *engine, const QStringRef &, const QStringRef &, bool *ok) const; + int scopedEnumValue(QQmlEnginePrivate *engine, QStringView, QStringView, bool *ok) const; int inlineComponentObjectId() const; void setInlineComponentObjectId(int id) const; // TODO: const setters are BAD diff --git a/src/qml/qml/qqmltypecompiler.cpp b/src/qml/qml/qqmltypecompiler.cpp index 6a4966ffba..a9f5cdbf8d 100644 --- a/src/qml/qml/qqmltypecompiler.cpp +++ b/src/qml/qml/qqmltypecompiler.cpp @@ -249,7 +249,7 @@ QQmlJS::MemoryPool *QQmlTypeCompiler::memoryPool() return document->jsParserEngine.pool(); } -QStringRef QQmlTypeCompiler::newStringRef(const QString &string) +QStringView QQmlTypeCompiler::newStringRef(const QString &string) { return document->jsParserEngine.newStringRef(string); } @@ -468,7 +468,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio QQmlJS::AST::FormalParameterList *paramList = nullptr; for (const QString ¶m : qAsConst(parameters)) { - QStringRef paramNameRef = compiler->newStringRef(param); + QStringView paramNameRef = compiler->newStringRef(param); QQmlJS::AST::PatternElement *b = new (pool) QQmlJS::AST::PatternElement(paramNameRef, nullptr); paramList = new (pool) QQmlJS::AST::FormalParameterList(paramList, b); @@ -551,7 +551,7 @@ bool QQmlEnumTypeResolver::resolveEnumBindings() return true; } -bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &, int enumValue, bool) +bool QQmlEnumTypeResolver::assignEnumToBinding(QmlIR::Binding *binding, QStringView, int enumValue, bool) { binding->type = QV4::CompiledData::Binding::Type_Number; binding->value.constantValueIndex = compiler->registerConstant(QV4::Encode((double)enumValue)); @@ -592,9 +592,9 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj, QHashedStringRef typeName(string.constData(), dot); const bool isQtObject = (typeName == QLatin1String("Qt")); - const QStringRef scopedEnumName = (dot2 != -1 ? string.midRef(dot + 1, dot2 - dot - 1) : QStringRef()); + const QStringView scopedEnumName = (dot2 != -1 ? QStringView{string}.mid(dot + 1, dot2 - dot - 1) : QStringView()); // ### consider supporting scoped enums in Qt namespace - const QStringRef enumValue = string.midRef(!isQtObject && dot2 != -1 ? dot2 + 1 : dot + 1); + const QStringView enumValue = QStringView{string}.mid(!isQtObject && dot2 != -1 ? dot2 + 1 : dot + 1); if (isIntProp) { // ### C++11 allows enums to be other integral types. Should we support other integral types here? // Allow enum assignment to ints. @@ -652,7 +652,7 @@ bool QQmlEnumTypeResolver::tryQualifiedEnumAssignment(const QmlIR::Object *obj, return assignEnumToBinding(binding, enumValue, value, isQtObject); } -int QQmlEnumTypeResolver::evaluateEnum(const QString &scope, const QStringRef &enumName, const QStringRef &enumValue, bool *ok) const +int QQmlEnumTypeResolver::evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const { Q_ASSERT_X(ok, "QQmlEnumTypeResolver::evaluateEnum", "ok must not be a null pointer"); *ok = false; @@ -1104,15 +1104,15 @@ QQmlComponentAndAliasResolver::resolveAliasesInObject(int objectIndex, const QString aliasPropertyValue = stringAt(alias->propertyNameIndex); - QStringRef property; - QStringRef subProperty; + QStringView property; + QStringView subProperty; const int propertySeparator = aliasPropertyValue.indexOf(QLatin1Char('.')); if (propertySeparator != -1) { - property = aliasPropertyValue.leftRef(propertySeparator); - subProperty = aliasPropertyValue.midRef(propertySeparator + 1); + property = QStringView{aliasPropertyValue}.left(propertySeparator); + subProperty = QStringView{aliasPropertyValue}.mid(propertySeparator + 1); } else - property = QStringRef(&aliasPropertyValue, 0, aliasPropertyValue.length()); + property = QStringView(aliasPropertyValue); QQmlPropertyIndex propIdx; diff --git a/src/qml/qml/qqmltypecompiler_p.h b/src/qml/qml/qqmltypecompiler_p.h index 883fbf0d68..66562251f9 100644 --- a/src/qml/qml/qqmltypecompiler_p.h +++ b/src/qml/qml/qqmltypecompiler_p.h @@ -118,7 +118,7 @@ public: void setComponentRoots(const QVector<quint32> &roots) { m_componentRoots = roots; } const QVector<quint32> &componentRoots() const { return m_componentRoots; } QQmlJS::MemoryPool *memoryPool(); - QStringRef newStringRef(const QString &string); + QStringView newStringRef(const QString &string); const QV4::Compiler::StringTableGenerator *stringPool() const; const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; } @@ -207,15 +207,15 @@ public: bool resolveEnumBindings(); private: - bool assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &enumName, int enumValue, bool isQtObject); + bool assignEnumToBinding(QmlIR::Binding *binding, QStringView enumName, int enumValue, bool isQtObject); bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject) { - return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject); + return assignEnumToBinding(binding, QStringView(enumName), enumValue, isQtObject); } bool tryQualifiedEnumAssignment(const QmlIR::Object *obj, const QQmlPropertyCache *propertyCache, const QQmlPropertyData *prop, QmlIR::Binding *binding); - int evaluateEnum(const QString &scope, const QStringRef &enumName, const QStringRef &enumValue, bool *ok) const; + int evaluateEnum(const QString &scope, QStringView enumName, QStringView enumValue, bool *ok) const; const QVector<QmlIR::Object*> &qmlObjects; diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp index 32f5bca8d9..d41685b047 100644 --- a/src/qml/qml/qqmltypedata.cpp +++ b/src/qml/qml/qqmltypedata.cpp @@ -358,7 +358,7 @@ void QQmlTypeData::done() error.setUrl(url()); error.setLine(qmlConvertSourceCoordinate<quint32, int>(type.location.line)); error.setColumn(qmlConvertSourceCoordinate<quint32, int>(type.location.column)); - error.setDescription(QQmlTypeLoader::tr("Type %1 has no inline component type called %2").arg(typeName.leftRef(lastDot), type.type.pendingResolutionName())); + error.setDescription(QQmlTypeLoader::tr("Type %1 has no inline component type called %2").arg(QStringView{typeName}.left(lastDot), type.type.pendingResolutionName())); errors.prepend(error); setError(errors); return; @@ -505,7 +505,7 @@ void QQmlTypeData::done() // associate inline components to root component { - auto typeName = finalUrlString().splitRef(u'/').last().split(u'.').first().toString(); + auto typeName = QStringView{finalUrlString()}.split(u'/').last().split(u'.').first().toString(); // typeName can be empty if a QQmlComponent was constructed with an empty QUrl parameter if (!typeName.isEmpty() && typeName.at(0).isUpper() && !m_inlineComponentData.isEmpty()) { QHashedStringRef const hashedStringRef { typeName }; @@ -529,7 +529,7 @@ void QQmlTypeData::done() for (int scriptIndex = 0; scriptIndex < m_scripts.count(); ++scriptIndex) { const QQmlTypeData::ScriptReference &script = m_scripts.at(scriptIndex); - QStringRef qualifier(&script.qualifier); + QStringView qualifier(script.qualifier); QString enclosingNamespace; const int lastDotIndex = qualifier.lastIndexOf(QLatin1Char('.')); diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 41b8f626f7..9b06bd77ca 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -728,7 +728,7 @@ ReturnedValue Text::method_isElementContentWhitespace(const FunctionObject *b, c if (!r) RETURN_UNDEFINED(); - return Encode(QStringRef(&r->d()->d->data).trimmed().isEmpty()); + return Encode(QStringView(r->d()->d->data).trimmed().isEmpty()); } ReturnedValue Text::method_wholeText(const FunctionObject *b, const Value *thisObject, const Value *, int) diff --git a/src/qml/qmldirparser/qqmldirparser.cpp b/src/qml/qmldirparser/qqmldirparser.cpp index a8a450d2ca..e4d916a10f 100644 --- a/src/qml/qmldirparser/qqmldirparser.cpp +++ b/src/qml/qmldirparser/qqmldirparser.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE -static int parseInt(const QStringRef &str, bool *ok) +static int parseInt(QStringView str, bool *ok) { int pos = 0; int number = 0; @@ -65,9 +65,9 @@ static QTypeRevision parseVersion(const QString &str) const int dotIndex = str.indexOf(QLatin1Char('.')); if (dotIndex != -1 && str.indexOf(QLatin1Char('.'), dotIndex + 1) == -1) { bool ok = false; - const int major = parseInt(QStringRef(&str, 0, dotIndex), &ok); + const int major = parseInt(QStringView(str).left(dotIndex), &ok); if (!ok) return QTypeRevision(); - const int minor = parseInt(QStringRef(&str, dotIndex + 1, str.length() - dotIndex - 1), &ok); + const int minor = parseInt(QStringView(str).mid(dotIndex + 1, str.length() - dotIndex - 1), &ok); return ok ? QTypeRevision::fromVersion(major, minor) : QTypeRevision(); } return QTypeRevision(); diff --git a/src/qml/qmldirparser/qqmlimportresolver.cpp b/src/qml/qmldirparser/qqmlimportresolver.cpp index d427706140..25b366556d 100644 --- a/src/qml/qmldirparser/qqmlimportresolver.cpp +++ b/src/qml/qmldirparser/qqmlimportresolver.cpp @@ -54,13 +54,13 @@ enum ImportVersion { FullyVersioned, PartiallyVersioned, Unversioned }; - base/QtQml.2/Models - base/QtQml/Models */ -QStringList qQmlResolveImportPaths(const QString &uri, const QStringList &basePaths, +QStringList qQmlResolveImportPaths(QStringView uri, const QStringList &basePaths, QTypeRevision version) { static const QLatin1Char Slash('/'); static const QLatin1Char Backslash('\\'); - const QVector<QStringRef> parts = uri.splitRef(QLatin1Char('.'), Qt::SkipEmptyParts); + const QVector<QStringView> parts = uri.split(u'.', Qt::SkipEmptyParts); QStringList importPaths; // fully & partially versioned parts + 1 unversioned for each base path @@ -81,7 +81,7 @@ QStringList qQmlResolveImportPaths(const QString &uri, const QStringList &basePa return QString(); }; - auto joinStringRefs = [](const QVector<QStringRef> &refs, const QChar &sep) { + auto joinStringRefs = [](const QVector<QStringView> &refs, const QChar &sep) { QString str; for (auto it = refs.cbegin(); it != refs.cend(); ++it) { if (it != refs.cbegin()) diff --git a/src/qml/qmldirparser/qqmlimportresolver_p.h b/src/qml/qmldirparser/qqmlimportresolver_p.h index bfc0592bf8..c2f49ee4ec 100644 --- a/src/qml/qmldirparser/qqmlimportresolver_p.h +++ b/src/qml/qmldirparser/qqmlimportresolver_p.h @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE -QStringList qQmlResolveImportPaths(const QString &uri, const QStringList &basePaths, +QStringList qQmlResolveImportPaths(QStringView uri, const QStringList &basePaths, QTypeRevision version); QT_END_NAMESPACE |