diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-10-05 07:29:16 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-07 23:38:48 +0200 |
commit | 958cd3ee1094a068b6d0ff27c73a4b3caff088ad (patch) | |
tree | 6d3816fedf5dab2307675fd6ef70d39758e246f5 /src/qml/jsruntime | |
parent | e8e03215654ca730243336a80453cf9396cbdf58 (diff) |
Port from container::count() and length() to size()
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8:
auto QtContainerClass = anyOf(
expr(hasType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))))).bind(o),
expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o));
makeRule(cxxMemberCallExpr(on(QtContainerClass),
callee(cxxMethodDecl(hasAnyName({"count", "length"),
parameterCountIs(0))))),
changeTo(cat(access(o, cat("size"), "()"))),
cat("use 'size()' instead of 'count()/length()'"))
a.k.a qt-port-to-std-compatible-api with config Scope: 'Container',
with the extended set of container classes recognized.
Change-Id: Idb1f75dfe2323bd1d9e8b4d58d54f1b4b80c7ed7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4dateobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4executableallocator_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4executablecompilationunit.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4function.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4globalobject.cpp | 14 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4identifiertable.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4jsonobject.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4module.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4propertykey.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexp.cpp | 12 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject.cpp | 18 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4stringiterator.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 58 |
18 files changed, 79 insertions, 79 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index 6f00ae7b6e..cbab5a239a 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -339,7 +339,7 @@ static inline double ParseString(const QString &s, double localTZA) }; const QChar *ch = s.constData(); - const QChar *end = ch + s.length(); + const QChar *end = ch + s.size(); uint format = Year; int current = 0; diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 7934fe6779..2800590712 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -954,13 +954,13 @@ Heap::Object *ExecutionEngine::newObject(Heap::InternalClass *internalClass) Heap::String *ExecutionEngine::newString(const QString &s) { - return memoryManager->allocWithStringData<String>(s.length() * sizeof(QChar), s); + return memoryManager->allocWithStringData<String>(s.size() * sizeof(QChar), s); } Heap::String *ExecutionEngine::newIdentifier(const QString &text) { Scope scope(this); - ScopedString s(scope, memoryManager->allocWithStringData<String>(text.length() * sizeof(QChar), text)); + ScopedString s(scope, memoryManager->allocWithStringData<String>(text.size() * sizeof(QChar), text)); s->toPropertyKey(); return s->d(); } @@ -1862,11 +1862,11 @@ QV4::ReturnedValue ExecutionEngine::fromData(QMetaType metaType, const void *ptr // directly against QList<QObject*>? const QList<QObject *> &list = *(const QList<QObject *>*)ptr; QV4::ScopedArrayObject a(scope, newArrayObject()); - a->arrayReserve(list.count()); + a->arrayReserve(list.size()); QV4::ScopedValue v(scope); - for (int ii = 0; ii < list.count(); ++ii) + for (int ii = 0; ii < list.size(); ++ii) a->arrayPut(ii, (v = QV4::QObjectWrapper::wrap(this, list.at(ii)))); - a->setArrayLengthUnchecked(list.count()); + a->setArrayLengthUnchecked(list.size()); return a.asReturnedValue(); } else if (auto flags = metaType.flags(); flags & QMetaType::PointerToQObject) { if (flags.testFlag(QMetaType::IsConst)) @@ -2327,7 +2327,7 @@ int ExecutionEngine::consoleCountHelper(const QString &file, quint16 line, quint void ExecutionEngine::setExtensionData(int index, Deletable *data) { - if (m_extensionData.count() <= index) + if (m_extensionData.size() <= index) m_extensionData.resize(index + 1); if (m_extensionData.at(index)) diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index aa4a6bacd9..e6471e796d 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -705,7 +705,7 @@ public: void setExtensionData(int, Deletable *); Deletable *extensionData(int index) const { - if (index < m_extensionData.count()) + if (index < m_extensionData.size()) return m_extensionData[index]; else return nullptr; diff --git a/src/qml/jsruntime/qv4executableallocator_p.h b/src/qml/jsruntime/qv4executableallocator_p.h index de9c0c7cd5..2f97c9ae6e 100644 --- a/src/qml/jsruntime/qv4executableallocator_p.h +++ b/src/qml/jsruntime/qv4executableallocator_p.h @@ -79,8 +79,8 @@ public: }; // for debugging / unit-testing - int freeAllocationCount() const { return freeAllocations.count(); } - int chunkCount() const { return chunks.count(); } + int freeAllocationCount() const { return freeAllocations.size(); } + int chunkCount() const { return chunks.size(); } struct ChunkOfPages { diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp index 0a3033a567..c355e064d4 100644 --- a/src/qml/jsruntime/qv4executablecompilationunit.cpp +++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp @@ -935,7 +935,7 @@ QString ExecutableCompilationUnit::translateFrom(TranslationDataIndex index) con const QString &path = fileName(); int lastSlash = path.lastIndexOf(QLatin1Char('/')); QStringView context = (lastSlash > -1) - ? QStringView{ path }.mid(lastSlash + 1, path.length() - lastSlash - 5) + ? QStringView{ path }.mid(lastSlash + 1, path.size() - lastSlash - 5) : QStringView(); QByteArray contextUtf8 = context.toUtf8(); QByteArray comment = stringAt(translation.commentIndex).toUtf8(); diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 666bd3a0de..e03c85d382 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -114,7 +114,7 @@ void Function::updateInternalClass(ExecutionEngine *engine, const QList<QByteArr QStringList parameterNames; // Resolve duplicate parameter names: - for (int i = 0, ei = parameters.count(); i != ei; ++i) { + for (int i = 0, ei = parameters.size(); i != ei; ++i) { const QByteArray ¶m = parameters.at(i); int duplicate = -1; diff --git a/src/qml/jsruntime/qv4globalobject.cpp b/src/qml/jsruntime/qv4globalobject.cpp index 5357b72477..32e93cedb4 100644 --- a/src/qml/jsruntime/qv4globalobject.cpp +++ b/src/qml/jsruntime/qv4globalobject.cpp @@ -29,7 +29,7 @@ static QString escape(const QString &input) { QString output; output.reserve(input.size() * 3); - const int length = input.length(); + const int length = input.size(); for (int i = 0; i < length; ++i) { ushort uc = input.at(i).unicode(); if (uc < 0x100) { @@ -60,9 +60,9 @@ static QString escape(const QString &input) static QString unescape(const QString &input) { QString result; - result.reserve(input.length()); + result.reserve(input.size()); int i = 0; - const int length = input.length(); + const int length = input.size(); while (i < length) { QChar c = input.at(i++); if ((c == u'%') && (i + 1 < length)) { @@ -110,7 +110,7 @@ static QString encode(const QString &input, const char *unescapedSet, bool *ok) { *ok = true; QString output; - const int length = input.length(); + const int length = input.size(); int i = 0; while (i < length) { const QChar c = input.at(i); @@ -184,8 +184,8 @@ static QString decode(const QString &input, DecodeMode decodeMode, bool *ok) { *ok = true; QString output; - output.reserve(input.length()); - const int length = input.length(); + output.reserve(input.size()); + const int length = input.size(); int i = 0; const QChar percent = QLatin1Char('%'); while (i < length) { @@ -378,7 +378,7 @@ ReturnedValue GlobalFunctions::method_parseInt(const FunctionObject *b, const Va CHECK_EXCEPTION(); const QChar *pos = trimmed.constData(); - const QChar *end = pos + trimmed.length(); + const QChar *end = pos + trimmed.size(); int sign = 1; // 3 if (pos != end) { diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp index 5b0c2f25ee..e3cde9b7c7 100644 --- a/src/qml/jsruntime/qv4identifiertable.cpp +++ b/src/qml/jsruntime/qv4identifiertable.cpp @@ -100,7 +100,7 @@ void IdentifierTable::addEntry(Heap::StringOrSymbol *str) Heap::String *IdentifierTable::insertString(const QString &s) { uint subtype; - uint hash = String::createHashValue(s.constData(), s.length(), &subtype); + uint hash = String::createHashValue(s.constData(), s.size(), &subtype); if (subtype == Heap::String::StringType_ArrayIndex) { Heap::String *str = engine->newString(s); str->stringHash = hash; @@ -133,7 +133,7 @@ Heap::Symbol *IdentifierTable::insertSymbol(const QString &s) Q_ASSERT(s.at(0) == QLatin1Char('@')); uint subtype; - uint hash = String::createHashValue(s.constData(), s.length(), &subtype); + uint hash = String::createHashValue(s.constData(), s.size(), &subtype); uint idx = hash % alloc; while (Heap::StringOrSymbol *e = entriesByHash[idx]) { if (e->stringHash == hash && e->toQString() == s) @@ -252,7 +252,7 @@ void IdentifierTable::sweep() PropertyKey IdentifierTable::asPropertyKey(const QString &s) { uint subtype; - const uint hash = String::createHashValue(s.constData(), s.length(), &subtype); + const uint hash = String::createHashValue(s.constData(), s.size(), &subtype); if (subtype == Heap::String::StringType_ArrayIndex) return PropertyKey::fromArrayIndex(hash); return resolveStringEntry(s, hash, subtype)->identifier; diff --git a/src/qml/jsruntime/qv4jsonobject.cpp b/src/qml/jsruntime/qv4jsonobject.cpp index 592e9079f1..4643195cfd 100644 --- a/src/qml/jsruntime/qv4jsonobject.cpp +++ b/src/qml/jsruntime/qv4jsonobject.cpp @@ -634,7 +634,7 @@ private: static QString quote(const QString &str) { QString product; - const int length = str.length(); + const int length = str.size(); product.reserve(length + 2); product += u'"'; for (int i = 0; i < length; ++i) { @@ -884,7 +884,7 @@ ReturnedValue JsonObject::method_parse(const FunctionObject *b, const Value *, c jtext = argv[0].toQString(); DEBUG << "parsing source = " << jtext; - JsonParser parser(v4, jtext.constData(), jtext.length()); + JsonParser parser(v4, jtext.constData(), jtext.size()); QJsonParseError error; ReturnedValue result = parser.parse(&error); if (error.error != QJsonParseError::NoError) { diff --git a/src/qml/jsruntime/qv4module.cpp b/src/qml/jsruntime/qv4module.cpp index 779eb77a36..1e1a059dfa 100644 --- a/src/qml/jsruntime/qv4module.cpp +++ b/src/qml/jsruntime/qv4module.cpp @@ -195,7 +195,7 @@ struct ModuleNamespaceIterator : ObjectOwnPropertyKeyIterator PropertyKey ModuleNamespaceIterator::next(const Object *o, Property *pd, PropertyAttributes *attrs) { const Module *module = static_cast<const Module *>(o); - if (exportIndex < exportedNames.count()) { + if (exportIndex < exportedNames.size()) { if (attrs) *attrs = Attr_Data; Scope scope(module->engine()); diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 77325580d3..d1e9b97307 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -1130,7 +1130,7 @@ void Heap::ArrayObject::init(const QStringList &list) // The result is a new Array object with length equal to the length // of the QStringList, and the elements being the QStringList's // elements converted to JS Strings. - int len = list.count(); + int len = list.size(); a->arrayReserve(len); ScopedValue v(scope); for (int ii = 0; ii < len; ++ii) diff --git a/src/qml/jsruntime/qv4propertykey.cpp b/src/qml/jsruntime/qv4propertykey.cpp index 8a3e1adc65..e07df07543 100644 --- a/src/qml/jsruntime/qv4propertykey.cpp +++ b/src/qml/jsruntime/qv4propertykey.cpp @@ -66,7 +66,7 @@ QV4::Heap::String *QV4::PropertyKey::asFunctionName(ExecutionEngine *engine, Fun QString str = s->toQString(); if (s->internalClass->vtable->isString) n += s->toQString(); - else if (str.length() > 1) + else if (str.size() > 1) n += QChar::fromLatin1('[') + QStringView{str}.mid(1) + QChar::fromLatin1(']'); } return engine->newString(n); diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index ef8c8c76d6..e5e7e7b3cb 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1401,8 +1401,8 @@ static ReturnedValue CallMethod(const QQmlObjectOrGadget &object, int index, QMe } } } - QVarLengthArray<void *, 9> argData(args.count()); - for (int ii = 0; ii < args.count(); ++ii) + QVarLengthArray<void *, 9> argData(args.size()); + for (int ii = 0; ii < args.size(); ++ii) argData[ii] = args[ii].dataPtr(); object.metacall(callType, index, argData.data()); @@ -2179,11 +2179,11 @@ ReturnedValue CallArgument::toValue(ExecutionEngine *engine) QList<QObject *> &list = *qlistPtr; Scope scope(engine); ScopedArrayObject array(scope, engine->newArrayObject()); - array->arrayReserve(list.count()); + array->arrayReserve(list.size()); ScopedValue v(scope); - for (int ii = 0; ii < list.count(); ++ii) + for (int ii = 0; ii < list.size(); ++ii) array->arrayPut(ii, (v = QObjectWrapper::wrap(engine, list.at(ii)))); - array->setArrayLengthUnchecked(list.count()); + array->setArrayLengthUnchecked(list.size()); return array.asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4regexp.cpp b/src/qml/jsruntime/qv4regexp.cpp index 0c039967ba..be7ff77603 100644 --- a/src/qml/jsruntime/qv4regexp.cpp +++ b/src/qml/jsruntime/qv4regexp.cpp @@ -49,7 +49,7 @@ uint RegExp::match(const QString &string, int start, uint *matchOffsets) uint ret = JSC::Yarr::offsetNoMatch; #if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS) char buffer[8192]; - ret = uint(priv->jitCode->execute(s.characters16(), start, s.length(), + ret = uint(priv->jitCode->execute(s.characters16(), start, s.size(), (int*)matchOffsets, buffer, 8192).start); #else ret = uint(priv->jitCode->execute(s.characters16(), start, s.length(), @@ -74,18 +74,18 @@ uint RegExp::match(const QString &string, int start, uint *matchOffsets) } #endif // ENABLE(YARR_JIT) - return JSC::Yarr::interpret(byteCode(), s.characters16(), string.length(), start, matchOffsets); + return JSC::Yarr::interpret(byteCode(), s.characters16(), string.size(), start, matchOffsets); } QString RegExp::getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement) { QString result; - int matchedLength = matched.length(); - Q_ASSERT(position >= 0 && position <= str.length()); + int matchedLength = matched.size(); + Q_ASSERT(position >= 0 && position <= str.size()); int tailPos = position + matchedLength; int seenDollar = -1; - for (int i = 0; i < replacement.length(); ++i) { + for (int i = 0; i < replacement.size(); ++i) { QChar ch = replacement.at(i); if (seenDollar >= 0) { if (ch.unicode() == '$') { @@ -98,7 +98,7 @@ QString RegExp::getSubstitution(const QString &matched, const QString &str, int result += str.mid(tailPos); } else if (ch.unicode() >= '0' && ch.unicode() <= '9') { int n = ch.unicode() - '0'; - if (i + 1 < replacement.length()) { + if (i + 1 < replacement.size()) { ch = replacement.at(i + 1); if (ch.unicode() >= '0' && ch.unicode() <= '9') { n = n*10 + (ch.unicode() - '0'); diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 1b62717efc..acb9f0acfc 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -46,7 +46,7 @@ void Heap::RegExpObject::init(QV4::RegExp *value) static QString minimalPattern(const QString &pattern) { QString ecmaPattern; - int len = pattern.length(); + int len = pattern.size(); ecmaPattern.reserve(len); int i = 0; const QChar *wc = pattern.unicode(); @@ -144,7 +144,7 @@ ReturnedValue RegExpObject::builtinExec(ExecutionEngine *engine, const String *s Scope scope(engine); int offset = (global() || sticky()) ? lastIndex() : 0; - if (offset < 0 || offset > s.length()) { + if (offset < 0 || offset > s.size()) { setLastIndex(0); RETURN_RESULT(Encode::null()); } @@ -168,7 +168,7 @@ ReturnedValue RegExpObject::builtinExec(ExecutionEngine *engine, const String *s int len = value()->captureCount(); array->arrayReserve(len); ScopedValue v(scope); - int strlen = s.length(); + int strlen = s.size(); for (int i = 0; i < len; ++i) { int start = matchOffsets[i * 2]; int end = matchOffsets[i * 2 + 1]; @@ -230,7 +230,7 @@ uint parseFlags(Scope &scope, const QV4::Value *f) if (scope.hasException()) return flags; QString str = s->toQString(); - for (int i = 0; i < str.length(); ++i) { + for (int i = 0; i < str.size(); ++i) { if (str.at(i) == QLatin1Char('g') && !(flags & CompiledData::RegExp::RegExp_Global)) { flags |= CompiledData::RegExp::RegExp_Global; } else if (str.at(i) == QLatin1Char('i') && !(flags & CompiledData::RegExp::RegExp_IgnoreCase)) { @@ -380,7 +380,7 @@ ReturnedValue RegExpPrototype::execFirstMatch(const FunctionObject *b, const Val QString s = str->toQString(); int offset = r->lastIndex(); - if (offset < 0 || offset > s.length()) { + if (offset < 0 || offset > s.size()) { r->setLastIndex(0); RETURN_RESULT(Encode::null()); } @@ -516,7 +516,7 @@ ReturnedValue RegExpPrototype::method_get_ignoreCase(const FunctionObject *f, co static int advanceStringIndex(int index, const QString &str, bool unicode) { if (unicode) { - if (index < str.length() - 1 && + if (index < str.size() - 1 && str.at(index).isHighSurrogate() && str.at(index + 1).isLowSurrogate()) ++index; @@ -605,7 +605,7 @@ ReturnedValue RegExpPrototype::method_replace(const FunctionObject *f, const Val if (scope.hasException()) return Encode::undefined(); - int lengthS = s->toQString().length(); + int lengthS = s->toQString().size(); ScopedString replaceValue(scope); ScopedFunctionObject replaceFunction(scope, (argc > 1 ? argv[1] : Value::undefinedValue())); @@ -657,7 +657,7 @@ ReturnedValue RegExpPrototype::method_replace(const FunctionObject *f, const Val if (scope.hasException()) return Encode::undefined(); QString m = matchString->toQString(); - int matchLength = m.length(); + int matchLength = m.size(); v = resultObject->get(scope.engine->id_index()); int position = v->toInt32(); position = qMax(qMin(position, lengthS), 0); @@ -784,7 +784,7 @@ ReturnedValue RegExpPrototype::method_split(const FunctionObject *f, const Value return A->asReturnedValue(); QString S = s->toQString(); - int size = S.length(); + int size = S.size(); if (size == 0) { ScopedValue z(scope, exec(scope.engine, splitter, s)); if (z->isNull()) diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 01ee03bddc..71446ca746 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -388,7 +388,7 @@ double RuntimeHelpers::stringToNumber(const QString &string) // libdoubleconversion sources. The same maximum value would be represented by roughly 3.5 times // as many binary digits. const int excessiveLength = 16 * 1024; - if (string.length() > excessiveLength) + if (string.size() > excessiveLength) return qQNaN(); const QStringView s = QStringView(string).trimmed(); @@ -638,7 +638,7 @@ static Q_NEVER_INLINE ReturnedValue getElementIntFallback(ExecutionEngine *engin ScopedObject o(scope, object); if (!o) { if (const String *str = object.as<String>()) { - if (idx >= (uint)str->toQString().length()) { + if (idx >= (uint)str->toQString().size()) { return Encode::undefined(); } const QString s = str->toQString().mid(idx, 1); diff --git a/src/qml/jsruntime/qv4stringiterator.cpp b/src/qml/jsruntime/qv4stringiterator.cpp index 99f10c55b4..9cb2711efb 100644 --- a/src/qml/jsruntime/qv4stringiterator.cpp +++ b/src/qml/jsruntime/qv4stringiterator.cpp @@ -35,7 +35,7 @@ ReturnedValue StringIteratorPrototype::method_next(const FunctionObject *b, cons quint32 index = thisObject->d()->nextIndex; QString str = s->toQString(); - quint32 len = str.length(); + quint32 len = str.size(); if (index >= len) { thisObject->d()->iteratedString.set(scope.engine, nullptr); diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 614171503e..40d1f9bfaf 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -51,7 +51,7 @@ void Heap::StringObject::init(const QV4::String *str) Heap::String *Heap::StringObject::getIndex(uint index) const { QString str = string->toQString(); - if (index >= (uint)str.length()) + if (index >= (uint)str.size()) return nullptr; return internalClass->engine->newString(str.mid(index, 1)); } @@ -67,7 +67,7 @@ bool StringObject::virtualDeleteProperty(Managed *m, PropertyKey id) if (id.isArrayIndex()) { StringObject *o = static_cast<StringObject *>(m); uint index = id.asArrayIndex(); - if (index < static_cast<uint>(o->d()->string->toQString().length())) + if (index < static_cast<uint>(o->d()->string->toQString().size())) return false; } return Object::virtualDeleteProperty(m, id); @@ -83,7 +83,7 @@ struct StringObjectOwnPropertyKeyIterator : ObjectOwnPropertyKeyIterator PropertyKey StringObjectOwnPropertyKeyIterator::next(const QV4::Object *o, Property *pd, PropertyAttributes *attrs) { const StringObject *s = static_cast<const StringObject *>(o); - uint slen = s->d()->string->toQString().length(); + uint slen = s->d()->string->toQString().size(); if (arrayIndex < slen) { uint index = arrayIndex; ++arrayIndex; @@ -119,7 +119,7 @@ PropertyAttributes StringObject::virtualGetOwnProperty(const Managed *m, Propert if (id.isArrayIndex()) { const uint index = id.asArrayIndex(); const auto s = static_cast<const StringObject *>(m); - if (index < uint(s->d()->string->toQString().length())) { + if (index < uint(s->d()->string->toQString().size())) { if (p) p->value = s->getIndex(index); return Attr_NotConfigurable|Attr_NotWritable; @@ -338,7 +338,7 @@ ReturnedValue StringPrototype::method_charAt(const FunctionObject *b, const Valu pos = argv[0].toInteger(); QString result; - if (pos >= 0 && pos < str.length()) + if (pos >= 0 && pos < str.size()) result += str.at(pos); return Encode(v4->newString(result)); @@ -356,7 +356,7 @@ ReturnedValue StringPrototype::method_charCodeAt(const FunctionObject *b, const pos = argv[0].toInteger(); - if (pos >= 0 && pos < str.length()) + if (pos >= 0 && pos < str.size()) RETURN_RESULT(Encode(str.at(pos).unicode())); return Encode(qt_qnan()); @@ -419,11 +419,11 @@ ReturnedValue StringPrototype::method_endsWith(const FunctionObject *b, const Va if (v4->hasException) return Encode::undefined(); - double pos = value.length(); + double pos = value.size(); if (argc > 1) pos = argv[1].toInteger(); - if (pos == value.length()) + if (pos == value.size()) RETURN_RESULT(Encode(value.endsWith(searchString))); QStringView stringToSearch = QStringView{value}.left(pos); @@ -447,7 +447,7 @@ ReturnedValue StringPrototype::method_indexOf(const FunctionObject *b, const Val int index = -1; if (!value.isEmpty()) - index = value.indexOf(searchString, qMin(qMax(pos, 0.0), double(value.length()))); + index = value.indexOf(searchString, qMin(qMax(pos, 0.0), double(value.size()))); return Encode(index); } @@ -470,7 +470,7 @@ ReturnedValue StringPrototype::method_includes(const FunctionObject *b, const Va const Value &posArg = argv[1]; pos = posArg.toInteger(); if (!posArg.isInteger() && posArg.isNumber() && qIsInf(posArg.toNumber())) - pos = value.length(); + pos = value.size(); } if (pos == 0) @@ -497,8 +497,8 @@ ReturnedValue StringPrototype::method_lastIndexOf(const FunctionObject *b, const else position = std::trunc(position); - int pos = std::trunc(qMin(qMax(position, 0.0), double(value.length()))); - if (!searchString.isEmpty() && pos == value.length()) + int pos = std::trunc(qMin(qMax(position, 0.0), double(value.size()))); + if (!searchString.isEmpty() && pos == value.size()) --pos; if (searchString.isNull() && pos == 0) RETURN_RESULT(Encode(-1)); @@ -607,12 +607,12 @@ ReturnedValue StringPrototype::method_padEnd(const FunctionObject *f, const Valu return s->asReturnedValue(); QString padded = s->toQString(); - int oldLength = padded.length(); + int oldLength = padded.size(); int toFill = maxLen - oldLength; padded.resize(maxLen); QChar *ch = padded.data() + oldLength; while (toFill) { - int copy = qMin(fillString.length(), toFill); + int copy = qMin(fillString.size(), toFill); memcpy(ch, fillString.constData(), copy*sizeof(QChar)); toFill -= copy; ch += copy; @@ -646,13 +646,13 @@ ReturnedValue StringPrototype::method_padStart(const FunctionObject *f, const Va return s->asReturnedValue(); QString original = s->toQString(); - int oldLength = original.length(); + int oldLength = original.size(); int toFill = maxLen - oldLength; QString padded; padded.resize(maxLen); QChar *ch = padded.data(); while (toFill) { - int copy = qMin(fillString.length(), toFill); + int copy = qMin(fillString.size(), toFill); memcpy(ch, fillString.constData(), copy*sizeof(QChar)); toFill -= copy; ch += copy; @@ -682,9 +682,9 @@ ReturnedValue StringPrototype::method_repeat(const FunctionObject *b, const Valu static void appendReplacementString(QString *result, const QString &input, const QString& replaceValue, uint* matchOffsets, int captureCount) { - result->reserve(result->length() + replaceValue.length()); - for (int i = 0; i < replaceValue.length(); ++i) { - if (replaceValue.at(i) == QLatin1Char('$') && i < replaceValue.length() - 1) { + result->reserve(result->length() + replaceValue.size()); + for (int i = 0; i < replaceValue.size(); ++i) { + if (replaceValue.at(i) == QLatin1Char('$') && i < replaceValue.size() - 1) { ushort ch = replaceValue.at(i + 1).unicode(); uint substStart = JSC::Yarr::offsetNoMatch; uint substEnd = JSC::Yarr::offsetNoMatch; @@ -703,12 +703,12 @@ static void appendReplacementString(QString *result, const QString &input, const skip = 1; } else if (ch == '\'') { substStart = matchOffsets[1]; - substEnd = input.length(); + substEnd = input.size(); skip = 1; } else if (ch >= '0' && ch <= '9') { uint capture = ch - '0'; skip = 1; - if (i < replaceValue.length() - 2) { + if (i < replaceValue.size() - 2) { ch = replaceValue.at(i + 2).unicode(); if (ch >= '0' && ch <= '9') { uint c = capture*10 + ch - '0'; @@ -793,7 +793,7 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val if (idx != -1) { numStringMatches = 1; matchOffsets[0] = idx; - matchOffsets[1] = idx + searchString.length(); + matchOffsets[1] = idx + searchString.size(); } } @@ -802,7 +802,7 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val ScopedValue replaceValue(scope, argc > 1 ? argv[1] : Value::undefinedValue()); ScopedFunctionObject searchCallback(scope, replaceValue); if (!!searchCallback) { - result.reserve(string.length() + 10*numStringMatches); + result.reserve(string.size() + 10*numStringMatches); ScopedValue entry(scope); Value *arguments = scope.alloc(numCaptures + 2); int lastEnd = 0; @@ -832,7 +832,7 @@ ReturnedValue StringPrototype::method_replace(const FunctionObject *b, const Val result += QStringView{string}.mid(lastEnd); } else { QString newString = replaceValue->toQString(); - result.reserve(string.length() + numStringMatches*newString.size()); + result.reserve(string.size() + numStringMatches*newString.size()); int lastEnd = 0; for (int i = 0; i < numStringMatches; ++i) { @@ -975,7 +975,7 @@ ReturnedValue StringPrototype::method_split(const FunctionObject *b, const Value } else { QString separator = separatorValue->toQString(); if (separator.isEmpty()) { - for (uint i = 0; i < qMin(limit, uint(text.length())); ++i) + for (uint i = 0; i < qMin(limit, uint(text.size())); ++i) array->push_back((s = scope.engine->newString(text.mid(i, 1)))); return array.asReturnedValue(); } @@ -1033,7 +1033,7 @@ ReturnedValue StringPrototype::method_substr(const FunctionObject *b, const Valu if (argc > 1) length = argv[1].toInteger(); - double count = value.length(); + double count = value.size(); if (start < 0) start = qMax(count + start, 0.0); @@ -1051,7 +1051,7 @@ ReturnedValue StringPrototype::method_substring(const FunctionObject *b, const V if (v4->hasException) return QV4::Encode::undefined(); - int length = value.length(); + int length = value.size(); double start = 0; double end = length; @@ -1124,11 +1124,11 @@ ReturnedValue StringPrototype::method_trim(const FunctionObject *b, const Value const QChar *chars = s.constData(); int start, end; - for (start = 0; start < s.length(); ++start) { + for (start = 0; start < s.size(); ++start) { if (!chars[start].isSpace() && chars[start].unicode() != 0xfeff) break; } - for (end = s.length() - 1; end >= start; --end) { + for (end = s.size() - 1; end >= start; --end) { if (!chars[end].isSpace() && chars[end].unicode() != 0xfeff) break; } |