diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-01-24 13:16:55 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-31 11:13:48 +0100 |
commit | 426b5647b6ac584cfa0a45ab932d4a4dfbcbadc4 (patch) | |
tree | 32ec22afc7ee39b6f9a3f4dd47a45c472f7d77e4 /src/qml/jsruntime/qv4lookup.cpp | |
parent | e3219a1f7143c52fad7f5c5266327e199d02c6d6 (diff) |
Implement Lookup::indexedSetter
use this instead of the generic runtime method. This gives
around 10% speedup for array heavy Javascript such
as crypto.js.
Change-Id: Ic8f478c5b18893f2ef49e3f658b1ef24ae22e64f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4lookup.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4lookup.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index c9d22523a9..4a75272843 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -180,6 +180,63 @@ ReturnedValue Lookup::indexedGetterObjectInt(Lookup *l, const ValueRef object, c return indexedGetterFallback(l, object, index); } +void Lookup::indexedSetterGeneric(Lookup *l, const ValueRef object, const ValueRef index, const ValueRef v) +{ + if (object->isObject()) { + Object *o = object->objectValue(); + if (o->arrayData && o->arrayData->type == ArrayData::Simple && index->asArrayIndex() < UINT_MAX) { + l->indexedSetter = indexedSetterObjectInt; + indexedSetterObjectInt(l, object, index, v); + return; + } + } + indexedSetterFallback(l, object, index, v); +} + +void Lookup::indexedSetterFallback(Lookup *l, const ValueRef object, const ValueRef index, const ValueRef value) +{ + ExecutionContext *ctx = l->engine->currentContext(); + Scope scope(ctx); + ScopedObject o(scope, object->toObject(ctx)); + if (scope.engine->hasException) + return; + + uint idx = index->asArrayIndex(); + if (idx < UINT_MAX) { + if (o->arrayData && o->arrayData->type == ArrayData::Simple) { + SimpleArrayData *s = static_cast<SimpleArrayData *>(o->arrayData); + if (s && idx < s->len && !s->data[idx].isEmpty()) { + s->data[idx] = value; + return; + } + } + o->putIndexed(idx, value); + return; + } + + ScopedString name(scope, index->toString(ctx)); + o->put(name, value); +} + +void Lookup::indexedSetterObjectInt(Lookup *l, const ValueRef object, const ValueRef index, const ValueRef v) +{ + uint idx = index->asArrayIndex(); + if (idx == UINT_MAX || !object->isObject()) { + indexedSetterGeneric(l, object, index, v); + return; + } + + Object *o = object->objectValue(); + if (o->arrayData && o->arrayData->type == ArrayData::Simple) { + SimpleArrayData *s = static_cast<SimpleArrayData *>(o->arrayData); + if (idx < s->len && !s->data[idx].isEmpty()) { + s->data[idx] = v; + return; + } + } + indexedSetterFallback(l, object, index, v); +} + ReturnedValue Lookup::getterGeneric(QV4::Lookup *l, const ValueRef object) { if (Object *o = object->asObject()) |