diff options
author | Lars Knoll <[email protected]> | 2014-01-09 11:05:08 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-01-20 21:14:27 +0100 |
commit | 5c25379cd1889dc16187c0ec62f32d2b17a320cf (patch) | |
tree | 23bb7bef5b2378ffe0e4193bf753811f4bf843f4 /src/qml/jsruntime/qv4arrayobject.cpp | |
parent | e2d9917878968986a9df21c9cfafc32a2360aee7 (diff) |
Save memory on array data
Store a simple vector of Values in the array data,
instead of a Vector of Property's. This halfes the
memory consumption on 64bit and simplifies our code.
If an indexed property gets converted to an accessor
property, we simply convert the ArrayData into a
SparseArrayData.
Add support in SparseArrayData to allocate double slots
(two Value's) to hold a full Property in case someone
sets an accessor on an indexed property.
Some methods still return a Property*, but this is safe, as
only the first Value in the Property pointer will ever get
accessed if the Property doesn't contain an accessor.
Change-Id: Ic9b0f309b09a2772a328d947a10faaf3be9fe56f
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4arrayobject.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4arrayobject.cpp | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index eb8a5301de..4ea979d16e 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -613,7 +613,7 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx) ScopedValue value(scope); - if ((instance->arrayData && instance->arrayType() != ArrayData::Simple) || instance->protoHasArray()) { + if (instance->hasAccessorProperty || (instance->arrayType() >= ArrayData::Sparse) || instance->protoHasArray()) { // lets be safe and slow for (uint i = fromIndex; i < len; ++i) { bool exists; @@ -625,31 +625,22 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx) } } else if (!instance->arrayData) { return Encode(-1); - } else if (instance->arrayType() == ArrayData::Sparse) { - for (SparseArrayNode *n = static_cast<SparseArrayData *>(instance->arrayData)->sparse->lowerBound(fromIndex); - n != static_cast<SparseArrayData *>(instance->arrayData)->sparse->end() && n->key() < len; n = n->nextNode()) { - value = instance->getValue(instance->arrayData->data + n->value, - instance->arrayData->attrs ? instance->arrayData->attrs[n->value] : Attr_Data); - if (scope.hasException()) - return Encode::undefined(); - if (__qmljs_strict_equal(value, searchValue)) - return Encode(n->key()); - } } else { + Q_ASSERT(instance->arrayType() == ArrayData::Simple || instance->arrayType() == ArrayData::Complex); if (len > instance->arrayData->length()) len = instance->arrayData->length(); - Property *pd = instance->arrayData->data; - Property *end = pd + len; - pd += fromIndex; - while (pd < end) { - if (!pd->value.isEmpty()) { - value = instance->getValue(pd, instance->arrayData->attributes(pd - instance->arrayData->data)); + SafeValue *val = instance->arrayData->data; + SafeValue *end = val + len; + val += fromIndex; + while (val < end) { + if (!val->isEmpty()) { + value = *val; if (scope.hasException()) return Encode::undefined(); if (__qmljs_strict_equal(value, searchValue)) - return Encode((uint)(pd - instance->arrayData->data)); + return Encode((uint)(val - instance->arrayData->data)); } - ++pd; + ++val; } } return Encode(-1); |