aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4setiterator.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@crimson.no>2018-06-01 01:27:47 +0200
committerRobin Burchell <robin.burchell@crimson.no>2018-06-27 16:13:42 +0000
commit3cda7df8ac8fc6f9a5562e89a4b047449dc3b2bc (patch)
tree199ab0e72318b88b64f9833c6fffd12a94b5db3d /src/qml/jsruntime/qv4setiterator.cpp
parentb4d31c9ff5f0c5821ea127c663532d9fc2cae43e (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/qv4setiterator.cpp')
-rw-r--r--src/qml/jsruntime/qv4setiterator.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4setiterator.cpp b/src/qml/jsruntime/qv4setiterator.cpp
index 715a4e30d5..4681a49bd6 100644
--- a/src/qml/jsruntime/qv4setiterator.cpp
+++ b/src/qml/jsruntime/qv4setiterator.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include <private/qv4iterator_p.h>
+#include <private/qv4estable_p.h>
#include <private/qv4setiterator_p.h>
#include <private/qv4setobject_p.h>
#include <private/qv4symbol_p.h>
@@ -63,34 +64,31 @@ ReturnedValue SetIteratorPrototype::method_next(const FunctionObject *b, const V
return scope.engine->throwTypeError(QLatin1String("Not a Set Iterator instance"));
Scoped<SetObject> s(scope, thisObject->d()->iteratedSet);
- quint32 index = thisObject->d()->setNextIndex;
+ uint index = thisObject->d()->setNextIndex;
IteratorKind itemKind = thisObject->d()->iterationKind;
-
if (!s) {
QV4::Value undefined = Primitive::undefinedValue();
return IteratorPrototype::createIterResultObject(scope.engine, undefined, true);
}
- Scoped<ArrayObject> arr(scope, s->d()->setArray);
+ Value *arguments = scope.alloc(2);
- while (index < arr->getLength()) {
- ScopedValue e(scope, arr->getIndexed(index));
- index += 1;
- thisObject->d()->setNextIndex = index;
+ while (index < s->d()->esTable->size()) {
+ s->d()->esTable->iterate(index, &arguments[0], &arguments[1]);
+ thisObject->d()->setNextIndex = index + 1;
if (itemKind == KeyValueIteratorKind) {
- // Return CreateIterResultObject(CreateArrayFromList(« e, e »), false).
ScopedArrayObject resultArray(scope, scope.engine->newArrayObject());
resultArray->arrayReserve(2);
- resultArray->arrayPut(0, e);
- resultArray->arrayPut(1, e);
+ resultArray->arrayPut(0, arguments[0]);
+ resultArray->arrayPut(1, arguments[0]); // yes, the key is repeated.
resultArray->setArrayLengthUnchecked(2);
return IteratorPrototype::createIterResultObject(scope.engine, resultArray, false);
}
- return IteratorPrototype::createIterResultObject(scope.engine, e, false);
+ return IteratorPrototype::createIterResultObject(scope.engine, arguments[0], false);
}
thisObject->d()->iteratedSet.set(scope.engine, nullptr);