diff options
author | Robin Burchell <robin.burchell@crimson.no> | 2018-06-01 01:27:47 +0200 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2018-06-27 16:13:42 +0000 |
commit | 3cda7df8ac8fc6f9a5562e89a4b047449dc3b2bc (patch) | |
tree | 199ab0e72318b88b64f9833c6fffd12a94b5db3d /src/qml/jsruntime/qv4mapiterator.cpp | |
parent | b4d31c9ff5f0c5821ea127c663532d9fc2cae43e (diff) |
Map/Set: Introduce QV4::ESTable
This removes the duplication of code between Map and Set by placing it
in a shared location, and will hopefully be a touch more efficient than
using ArrayObject.
In a followup patch, it will get faster, too.
Note: As a bonus, this also fixed a few more test failures: forEach
wasn't handling the object being changed during iteration.
Task-number: QTBUG-68545
Change-Id: I8bf6f9c5b2de030a02ce27a23b8c1da431ffeda4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4mapiterator.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4mapiterator.cpp | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4mapiterator.cpp b/src/qml/jsruntime/qv4mapiterator.cpp index 74b0dda791..7be7416e4a 100644 --- a/src/qml/jsruntime/qv4mapiterator.cpp +++ b/src/qml/jsruntime/qv4mapiterator.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include <private/qv4iterator_p.h> +#include <private/qv4estable_p.h> #include <private/qv4mapiterator_p.h> #include <private/qv4mapobject_p.h> #include <private/qv4symbol_p.h> @@ -63,7 +64,7 @@ ReturnedValue MapIteratorPrototype::method_next(const FunctionObject *b, const V return scope.engine->throwTypeError(QLatin1String("Not a Map Iterator instance")); Scoped<MapObject> s(scope, thisObject->d()->iteratedMap); - quint32 index = thisObject->d()->mapNextIndex; + uint index = thisObject->d()->mapNextIndex; IteratorKind itemKind = thisObject->d()->iterationKind; if (!s) { @@ -71,21 +72,18 @@ ReturnedValue MapIteratorPrototype::method_next(const FunctionObject *b, const V return IteratorPrototype::createIterResultObject(scope.engine, undefined, true); } - Scoped<ArrayObject> keys(scope, s->d()->mapKeys); - Scoped<ArrayObject> values(scope, s->d()->mapValues); + Value *arguments = scope.alloc(2); - while (index < keys->getLength()) { - ScopedValue sk(scope, keys->getIndexed(index)); - ScopedValue sv(scope, values->getIndexed(index)); - index += 1; - thisObject->d()->mapNextIndex = index; + while (index < s->d()->esTable->size()) { + s->d()->esTable->iterate(index, &arguments[0], &arguments[1]); + thisObject->d()->mapNextIndex = index + 1; ScopedValue result(scope); if (itemKind == KeyIteratorKind) { - result = sk; + result = arguments[0]; } else if (itemKind == ValueIteratorKind) { - result = sv; + result = arguments[1]; } else { Q_ASSERT(itemKind == KeyValueIteratorKind); @@ -93,8 +91,8 @@ ReturnedValue MapIteratorPrototype::method_next(const FunctionObject *b, const V Scoped<ArrayObject> resultArray(scope, result); resultArray->arrayReserve(2); - resultArray->arrayPut(0, sk); - resultArray->arrayPut(1, sv); + resultArray->arrayPut(0, arguments[0]); + resultArray->arrayPut(1, arguments[1]); resultArray->setArrayLengthUnchecked(2); } |