aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4arraydata.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-10-22 16:00:35 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-10-27 15:19:10 +0100
commit8539aa87345fc9a972d9b400fa42fd742b01d4ed (patch)
treec3b40f383f75871e4d545140062c10eb10bf98c4 /src/qml/jsruntime/qv4arraydata.cpp
parent51d8f62dacc9b37a50e522162d5438a624ee9168 (diff)
Reduce size of ArrayData by one pointer
The pointer to the real data is not required anymore, as it always follows the class itself. Like this we save one pointer of overhead, and one indirection when doing reads and writes of array data. Change-Id: If6afdac8e97b57420b50e7b7eb8979f77e8dbbcf Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4arraydata.cpp')
-rw-r--r--src/qml/jsruntime/qv4arraydata.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/qml/jsruntime/qv4arraydata.cpp b/src/qml/jsruntime/qv4arraydata.cpp
index 469081e683..c40f50153d 100644
--- a/src/qml/jsruntime/qv4arraydata.cpp
+++ b/src/qml/jsruntime/qv4arraydata.cpp
@@ -119,7 +119,7 @@ void ArrayData::realloc(Object *o, Type newType, uint requested, bool enforceAtt
while (alloc < requested)
alloc *= 2;
- size_t size = sizeof(ArrayData::Data) + alloc*sizeof(Value);
+ size_t size = sizeof(ArrayData::Data) + (alloc - 1)*sizeof(Value);
if (enforceAttributes)
size += alloc*sizeof(PropertyAttributes);
@@ -137,7 +137,6 @@ void ArrayData::realloc(Object *o, Type newType, uint requested, bool enforceAtt
}
newData->setAlloc(alloc);
newData->setType(newType);
- newData->d()->arrayData = reinterpret_cast<Value *>(newData->d() + 1);
newData->setAttrs(enforceAttributes ? reinterpret_cast<PropertyAttributes *>(newData->d()->arrayData + alloc) : 0);
o->setArrayData(newData);
@@ -417,10 +416,10 @@ uint SparseArrayData::allocate(Object *o, bool doubleSlot)
ReturnedValue SparseArrayData::get(const ArrayData *d, uint index)
{
const SparseArrayData *s = static_cast<const SparseArrayData *>(d);
- SparseArrayNode *n = s->sparse()->findNode(index);
- if (!n)
+ index = s->mappedIndex(index);
+ if (index == UINT_MAX)
return Primitive::emptyValue().asReturnedValue();
- return s->arrayData()[n->value].asReturnedValue();
+ return s->arrayData()[index].asReturnedValue();
}
bool SparseArrayData::put(Object *o, uint index, ValueRef value)
@@ -428,7 +427,7 @@ bool SparseArrayData::put(Object *o, uint index, ValueRef value)
if (value->isEmpty())
return true;
- const SparseArrayData *s = static_cast<const SparseArrayData *>(o->arrayData());
+ SparseArrayData *s = static_cast<SparseArrayData *>(o->arrayData());
SparseArrayNode *n = s->sparse()->insert(index);
Q_ASSERT(n->value == UINT_MAX || !o->arrayData()->attrs() || !o->arrayData()->attrs()[n->value].isAccessor());
if (n->value == UINT_MAX)
@@ -442,6 +441,7 @@ bool SparseArrayData::put(Object *o, uint index, ValueRef value)
bool SparseArrayData::del(Object *o, uint index)
{
SparseArrayData *dd = static_cast<SparseArrayData *>(o->arrayData());
+
SparseArrayNode *n = dd->sparse()->findNode(index);
if (!n)
return true;
@@ -567,14 +567,14 @@ bool SparseArrayData::putArray(Object *o, uint index, Value *values, uint n)
}
-uint ArrayData::append(Object *obj, const ArrayObject *otherObj, uint n)
+uint ArrayData::append(Object *obj, ArrayObject *otherObj, uint n)
{
Q_ASSERT(!obj->arrayData()->hasAttributes());
if (!n)
return obj->getLength();
- const ArrayData *other = otherObj->arrayData();
+ ArrayData *other = otherObj->arrayData();
if (other->isSparse())
obj->initSparseArray();
@@ -584,7 +584,7 @@ uint ArrayData::append(Object *obj, const ArrayObject *otherObj, uint n)
uint oldSize = obj->getLength();
if (other->isSparse()) {
- const SparseArrayData *os = static_cast<const SparseArrayData *>(other);
+ SparseArrayData *os = static_cast<SparseArrayData *>(other);
if (otherObj->hasAccessorProperty() && other->hasAttributes()) {
Scope scope(obj->engine());
ScopedValue v(scope);
@@ -599,7 +599,7 @@ uint ArrayData::append(Object *obj, const ArrayObject *otherObj, uint n)
obj->arraySet(oldSize + it->key(), ValueRef(os->arrayData()[it->value]));
}
} else {
- const SimpleArrayData *os = static_cast<const SimpleArrayData *>(other);
+ SimpleArrayData *os = static_cast<SimpleArrayData *>(other);
uint toCopy = n;
uint chunk = toCopy;
if (chunk > os->alloc() - os->d()->offset)
@@ -628,7 +628,7 @@ Property *ArrayData::insert(Object *o, uint index, bool isAccessor)
d->data(i) = Primitive::emptyValue();
d->len() = index + 1;
}
- return reinterpret_cast<Property *>(d->d()->arrayData + d->realIndex(index));
+ return reinterpret_cast<Property *>(d->d()->arrayData + d->mappedIndex(index));
}
}