diff options
author | Lars Knoll <[email protected]> | 2014-04-10 17:53:00 +0200 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2014-07-22 13:48:58 +0200 |
commit | 43df154aa1d3347d81d8c6eba09871da318c417e (patch) | |
tree | e41d7ff94dfa4c8a5292e3bfbc30b80afa225d39 /src | |
parent | f05f3a36b43ada6b37cda1ee4703fe857f8771da (diff) |
Move ArrayData over to new data layout
Change-Id: Ic51f37bea030b196f0fa35ab21e618447edaa25d
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4arraydata.cpp | 382 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4arraydata_p.h | 62 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4arrayobject.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4lookup.cpp | 22 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 24 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object_p.h | 15 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4objectproto.cpp | 20 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 4 |
9 files changed, 283 insertions, 252 deletions
diff --git a/src/qml/jsruntime/qv4arraydata.cpp b/src/qml/jsruntime/qv4arraydata.cpp index 71670146ff..3b9b2cbd26 100644 --- a/src/qml/jsruntime/qv4arraydata.cpp +++ b/src/qml/jsruntime/qv4arraydata.cpp @@ -90,19 +90,19 @@ void ArrayData::realloc(Object *o, Type newType, uint offset, uint alloc, bool e alloc = 8; if (d) { - bool hasAttrs = d->attrs; + bool hasAttrs = d->attrs(); enforceAttributes |= hasAttrs; - if (!offset && alloc <= d->alloc && newType == d->type && hasAttrs == enforceAttributes) + if (!offset && alloc <= d->alloc() && newType == d->type() && hasAttrs == enforceAttributes) return; - oldAlloc = d->alloc; - if (d->type < Sparse) { - offset = qMax(offset, static_cast<SimpleArrayData *>(d)->offset); - toCopy = static_cast<SimpleArrayData *>(d)->len; + oldAlloc = d->alloc(); + if (d->type() < Sparse) { + offset = qMax(offset, static_cast<SimpleArrayData *>(d)->offset()); + toCopy = static_cast<SimpleArrayData *>(d)->len(); } else { Q_ASSERT(!offset); - toCopy = d->alloc; + toCopy = d->alloc(); newType = Sparse; } } @@ -118,32 +118,32 @@ void ArrayData::realloc(Object *o, Type newType, uint offset, uint alloc, bool e size += sizeof(SimpleArrayData); SimpleArrayData *newData = static_cast<SimpleArrayData *>(o->engine()->memoryManager->allocManaged(size)); new (newData) SimpleArrayData(o->engine()); - newData->alloc = alloc - offset; - newData->type = newType; - newData->data = reinterpret_cast<Value *>(newData + 1) + offset; - newData->attrs = enforceAttributes ? reinterpret_cast<PropertyAttributes *>(newData->data + alloc) + offset : 0; - newData->offset = offset; - newData->len = d ? static_cast<SimpleArrayData *>(d)->len : 0; + newData->setAlloc(alloc - offset); + newData->setType(newType); + newData->setArrayData(reinterpret_cast<Value *>(newData + 1) + offset); + newData->setAttrs(enforceAttributes ? reinterpret_cast<PropertyAttributes *>(newData->arrayData() + alloc) + offset : 0); + newData->offset() = offset; + newData->len() = d ? static_cast<SimpleArrayData *>(d)->len() : 0; o->setArrayData(newData); } else { size += sizeof(SparseArrayData); SparseArrayData *newData = static_cast<SparseArrayData *>(o->engine()->memoryManager->allocManaged(size)); new (newData) SparseArrayData(o->engine()); - newData->alloc = alloc; - newData->type = newType; - newData->data = reinterpret_cast<Value *>(newData + 1); - newData->attrs = enforceAttributes ? reinterpret_cast<PropertyAttributes *>(newData->data + alloc) : 0; + newData->setAlloc(alloc); + newData->setType(newType); + newData->setArrayData(reinterpret_cast<Value *>(newData + 1)); + newData->setAttrs(enforceAttributes ? reinterpret_cast<PropertyAttributes *>(newData->arrayData() + alloc) : 0); o->setArrayData(newData); } if (d) { - memcpy(o->arrayData()->data, d->data, sizeof(Value)*toCopy); + memcpy(o->arrayData()->arrayData(), d->arrayData(), sizeof(Value)*toCopy); if (enforceAttributes) { - if (d->attrs) - memcpy(o->arrayData()->attrs, d->attrs, sizeof(PropertyAttributes)*toCopy); + if (d->attrs()) + memcpy(o->arrayData()->attrs(), d->attrs(), sizeof(PropertyAttributes)*toCopy); else for (uint i = 0; i < toCopy; ++i) - o->arrayData()->attrs[i] = Attr_Data; + o->arrayData()->attrs()[i] = Attr_Data; } } @@ -151,33 +151,33 @@ void ArrayData::realloc(Object *o, Type newType, uint offset, uint alloc, bool e return; SparseArrayData *newData = static_cast<SparseArrayData *>(o->arrayData()); - if (d && d->type == Sparse) { + if (d && d->type() == Sparse) { SparseArrayData *old = static_cast<SparseArrayData *>(d); - newData->sparse = old->sparse; - old->sparse = 0; - newData->freeList = old->freeList; + newData->setSparse(old->sparse()); + old->setSparse(0); + newData->freeList() = old->freeList(); } else { - newData->sparse = new SparseArray; - uint *lastFree = &newData->freeList; + newData->setSparse(new SparseArray); + uint *lastFree = &newData->freeList(); for (uint i = 0; i < toCopy; ++i) { - if (!newData->data[i].isEmpty()) { - SparseArrayNode *n = newData->sparse->insert(i); + if (!newData->arrayData()[i].isEmpty()) { + SparseArrayNode *n = newData->sparse()->insert(i); n->value = i; } else { *lastFree = i; - newData->data[i].tag = Value::Empty_Type; - lastFree = &newData->data[i].uint_32; + newData->arrayData()[i].tag = Value::Empty_Type; + lastFree = &newData->arrayData()[i].uint_32; } } } - uint *lastFree = &newData->freeList; - for (uint i = toCopy; i < newData->alloc; ++i) { + uint *lastFree = &newData->freeList(); + for (uint i = toCopy; i < newData->alloc(); ++i) { *lastFree = i; - newData->data[i].tag = Value::Empty_Type; - lastFree = &newData->data[i].uint_32; + newData->arrayData()[i].tag = Value::Empty_Type; + lastFree = &newData->arrayData()[i].uint_32; } - *lastFree = newData->alloc; + *lastFree = newData->alloc(); // ### Could explicitly free the old data } @@ -187,8 +187,8 @@ void SimpleArrayData::getHeadRoom(Object *o) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); Q_ASSERT(dd); - Q_ASSERT(!dd->offset); - uint offset = qMax(dd->len >> 2, (uint)16); + Q_ASSERT(!dd->offset()); + uint offset = qMax(dd->len() >> 2, (uint)16); realloc(o, Simple, offset, 0, false); } @@ -200,7 +200,7 @@ ArrayData *SimpleArrayData::reallocate(Object *o, uint n, bool enforceAttributes void ArrayData::ensureAttributes(Object *o) { - if (o->arrayData() && o->arrayData()->attrs) + if (o->arrayData() && o->arrayData()->attrs()) return; ArrayData::realloc(o, Simple, 0, 0, true); @@ -210,29 +210,29 @@ void ArrayData::ensureAttributes(Object *o) void SimpleArrayData::markObjects(Managed *d, ExecutionEngine *e) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(d); - uint l = dd->len; + uint l = dd->len(); for (uint i = 0; i < l; ++i) - dd->data[i].mark(e); + dd->arrayData()[i].mark(e); } ReturnedValue SimpleArrayData::get(const ArrayData *d, uint index) { const SimpleArrayData *dd = static_cast<const SimpleArrayData *>(d); - if (index >= dd->len) + if (index >= dd->len()) return Primitive::emptyValue().asReturnedValue(); - return dd->data[index].asReturnedValue(); + return dd->arrayData()[index].asReturnedValue(); } bool SimpleArrayData::put(Object *o, uint index, ValueRef value) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); - Q_ASSERT(index >= dd->len || !dd->attrs || !dd->attrs[index].isAccessor()); + Q_ASSERT(index >= dd->len() || !dd->attrs() || !dd->attrs()[index].isAccessor()); // ### honour attributes - dd->data[index] = value; - if (index >= dd->len) { - if (dd->attrs) - dd->attrs[index] = Attr_Data; - dd->len = index + 1; + dd->arrayData()[index] = value; + if (index >= dd->len()) { + if (dd->attrs()) + dd->attrs()[index] = Attr_Data; + dd->len() = index + 1; } return true; } @@ -240,46 +240,46 @@ bool SimpleArrayData::put(Object *o, uint index, ValueRef value) bool SimpleArrayData::del(Object *o, uint index) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); - if (index >= dd->len) + if (index >= dd->len()) return true; - if (!dd->attrs || dd->attrs[index].isConfigurable()) { - dd->data[index] = Primitive::emptyValue(); - if (dd->attrs) - dd->attrs[index] = Attr_Data; + if (!dd->attrs() || dd->attrs()[index].isConfigurable()) { + dd->arrayData()[index] = Primitive::emptyValue(); + if (dd->attrs()) + dd->attrs()[index] = Attr_Data; return true; } - if (dd->data[index].isEmpty()) + if (dd->arrayData()[index].isEmpty()) return true; return false; } void SimpleArrayData::setAttribute(Object *o, uint index, PropertyAttributes attrs) { - o->arrayData()->attrs[index] = attrs; + o->arrayData()->attrs()[index] = attrs; } PropertyAttributes SimpleArrayData::attribute(const ArrayData *d, uint index) { - return d->attrs[index]; + return d->attrs()[index]; } void SimpleArrayData::push_front(Object *o, Value *values, uint n) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); - Q_ASSERT(!dd->attrs); + Q_ASSERT(!dd->attrs()); for (int i = n - 1; i >= 0; --i) { - if (!dd->offset) { + if (!dd->offset()) { getHeadRoom(o); dd = static_cast<SimpleArrayData *>(o->arrayData()); } - --dd->offset; - --dd->data; - ++dd->len; - ++dd->alloc; - *dd->data = values[i].asReturnedValue(); + --dd->offset(); + --dd->arrayData(); + ++dd->len(); + ++dd->alloc(); + *dd->arrayData() = values[i].asReturnedValue(); } } @@ -287,92 +287,92 @@ void SimpleArrayData::push_front(Object *o, Value *values, uint n) ReturnedValue SimpleArrayData::pop_front(Object *o) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); - Q_ASSERT(!dd->attrs); - if (!dd->len) + Q_ASSERT(!dd->attrs()); + if (!dd->len()) return Encode::undefined(); - ReturnedValue v = dd->data[0].isEmpty() ? Encode::undefined() : dd->data[0].asReturnedValue(); - ++dd->offset; - ++dd->data; - --dd->len; - --dd->alloc; + ReturnedValue v = dd->arrayData()[0].isEmpty() ? Encode::undefined() : dd->arrayData()[0].asReturnedValue(); + ++dd->offset(); + ++dd->arrayData(); + --dd->len(); + --dd->alloc(); return v; } uint SimpleArrayData::truncate(Object *o, uint newLen) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); - if (dd->len < newLen) + if (dd->len() < newLen) return newLen; - if (dd->attrs) { - Value *it = dd->data + dd->len; - const Value *begin = dd->data + newLen; + if (dd->attrs()) { + Value *it = dd->arrayData() + dd->len(); + const Value *begin = dd->arrayData() + newLen; while (--it >= begin) { - if (!it->isEmpty() && !dd->attrs[it - dd->data].isConfigurable()) { - newLen = it - dd->data + 1; + if (!it->isEmpty() && !dd->attrs()[it - dd->arrayData()].isConfigurable()) { + newLen = it - dd->arrayData() + 1; break; } *it = Primitive::emptyValue(); } } - dd->len = newLen; + dd->len() = newLen; return newLen; } uint SimpleArrayData::length(const ArrayData *d) { - return static_cast<const SimpleArrayData *>(d)->len; + return static_cast<const SimpleArrayData *>(d)->len(); } bool SimpleArrayData::putArray(Object *o, uint index, Value *values, uint n) { SimpleArrayData *dd = static_cast<SimpleArrayData *>(o->arrayData()); - if (index + n > dd->alloc) { + if (index + n > dd->alloc()) { reallocate(o, index + n + 1, false); dd = static_cast<SimpleArrayData *>(o->arrayData()); } - for (uint i = dd->len; i < index; ++i) - dd->data[i] = Primitive::emptyValue(); + for (uint i = dd->len(); i < index; ++i) + dd->arrayData()[i] = Primitive::emptyValue(); for (uint i = 0; i < n; ++i) - dd->data[index + i] = values[i]; - dd->len = qMax(dd->len, index + n); + dd->arrayData()[index + i] = values[i]; + dd->len() = qMax(dd->len(), index + n); return true; } void SparseArrayData::free(ArrayData *d, uint idx) { - Q_ASSERT(d && d->type == ArrayData::Sparse); + Q_ASSERT(d && d->type() == ArrayData::Sparse); SparseArrayData *dd = static_cast<SparseArrayData *>(d); - Value *v = dd->data + idx; - if (dd->attrs && dd->attrs[idx].isAccessor()) { + Value *v = dd->arrayData() + idx; + if (dd->attrs() && dd->attrs()[idx].isAccessor()) { // double slot, free both. Order is important, so we have a double slot for allocation again afterwards. v[1].tag = Value::Empty_Type; - v[1].uint_32 = dd->freeList; + v[1].uint_32 = dd->freeList(); v[0].tag = Value::Empty_Type; v[0].uint_32 = idx + 1; } else { v->tag = Value::Empty_Type; - v->uint_32 = dd->freeList; + v->uint_32 = dd->freeList(); } - dd->freeList = idx; - if (dd->attrs) - dd->attrs[idx].clear(); + dd->freeList() = idx; + if (dd->attrs()) + dd->attrs()[idx].clear(); } void SparseArrayData::destroy(Managed *d) { SparseArrayData *dd = static_cast<SparseArrayData *>(d); - delete dd->sparse; + delete dd->sparse(); } void SparseArrayData::markObjects(Managed *d, ExecutionEngine *e) { SparseArrayData *dd = static_cast<SparseArrayData *>(d); - uint l = dd->alloc; + uint l = dd->alloc(); for (uint i = 0; i < l; ++i) - dd->data[i].mark(e); + dd->arrayData()[i].mark(e); } ArrayData *SparseArrayData::reallocate(Object *o, uint n, bool enforceAttributes) @@ -384,45 +384,45 @@ ArrayData *SparseArrayData::reallocate(Object *o, uint n, bool enforceAttributes // double slots are required for accessor properties uint SparseArrayData::allocate(Object *o, bool doubleSlot) { - Q_ASSERT(o->arrayData()->type == ArrayData::Sparse); + Q_ASSERT(o->arrayData()->type() == ArrayData::Sparse); SparseArrayData *dd = static_cast<SparseArrayData *>(o->arrayData()); if (doubleSlot) { - uint *last = &dd->freeList; + uint *last = &dd->freeList(); while (1) { - if (*last + 1 >= dd->alloc) { - reallocate(o, o->arrayData()->alloc + 2, true); + if (*last + 1 >= dd->alloc()) { + reallocate(o, o->arrayData()->alloc() + 2, true); dd = static_cast<SparseArrayData *>(o->arrayData()); - last = &dd->freeList; + last = &dd->freeList(); } - if (dd->data[*last].uint_32 == (*last + 1)) { + if (dd->arrayData()[*last].uint_32 == (*last + 1)) { // found two slots in a row uint idx = *last; - *last = dd->data[*last + 1].uint_32; - o->arrayData()->attrs[idx] = Attr_Accessor; + *last = dd->arrayData()[*last + 1].uint_32; + o->arrayData()->attrs()[idx] = Attr_Accessor; return idx; } - last = &dd->data[*last].uint_32; + last = &dd->arrayData()[*last].uint_32; } } else { - if (dd->alloc == dd->freeList) { - reallocate(o, o->arrayData()->alloc + 2, false); + if (dd->alloc() == dd->freeList()) { + reallocate(o, o->arrayData()->alloc() + 2, false); dd = static_cast<SparseArrayData *>(o->arrayData()); } - uint idx = dd->freeList; - dd->freeList = dd->data[idx].uint_32; - if (dd->attrs) - dd->attrs[idx] = Attr_Data; + uint idx = dd->freeList(); + dd->freeList() = dd->arrayData()[idx].uint_32; + if (dd->attrs()) + dd->attrs()[idx] = Attr_Data; return idx; } } ReturnedValue SparseArrayData::get(const ArrayData *d, uint index) { - SparseArrayNode *n = static_cast<const SparseArrayData *>(d)->sparse->findNode(index); + SparseArrayNode *n = static_cast<const SparseArrayData *>(d)->sparse()->findNode(index); if (!n) return Primitive::emptyValue().asReturnedValue(); - return d->data[n->value].asReturnedValue(); + return d->arrayData()[n->value].asReturnedValue(); } bool SparseArrayData::put(Object *o, uint index, ValueRef value) @@ -430,92 +430,92 @@ bool SparseArrayData::put(Object *o, uint index, ValueRef value) if (value->isEmpty()) return true; - SparseArrayNode *n = static_cast<SparseArrayData *>(o->arrayData())->sparse->insert(index); - Q_ASSERT(n->value == UINT_MAX || !o->arrayData()->attrs || !o->arrayData()->attrs[n->value].isAccessor()); + SparseArrayNode *n = static_cast<SparseArrayData *>(o->arrayData())->sparse()->insert(index); + Q_ASSERT(n->value == UINT_MAX || !o->arrayData()->attrs() || !o->arrayData()->attrs()[n->value].isAccessor()); if (n->value == UINT_MAX) n->value = allocate(o); - o->arrayData()->data[n->value] = value; - if (o->arrayData()->attrs) - o->arrayData()->attrs[n->value] = Attr_Data; + o->arrayData()->arrayData()[n->value] = value; + if (o->arrayData()->attrs()) + o->arrayData()->attrs()[n->value] = Attr_Data; return true; } bool SparseArrayData::del(Object *o, uint index) { SparseArrayData *dd = static_cast<SparseArrayData *>(o->arrayData()); - SparseArrayNode *n = dd->sparse->findNode(index); + SparseArrayNode *n = dd->sparse()->findNode(index); if (!n) return true; uint pidx = n->value; - Q_ASSERT(!dd->data[pidx].isEmpty()); + Q_ASSERT(!dd->arrayData()[pidx].isEmpty()); bool isAccessor = false; - if (dd->attrs) { - if (!dd->attrs[pidx].isConfigurable()) + if (dd->attrs()) { + if (!dd->attrs()[pidx].isConfigurable()) return false; - isAccessor = dd->attrs[pidx].isAccessor(); - dd->attrs[pidx] = Attr_Data; + isAccessor = dd->attrs()[pidx].isAccessor(); + dd->attrs()[pidx] = Attr_Data; } if (isAccessor) { // free up both indices - dd->data[pidx + 1].tag = Value::Undefined_Type; - dd->data[pidx + 1].uint_32 = static_cast<SparseArrayData *>(dd)->freeList; - dd->data[pidx].tag = Value::Undefined_Type; - dd->data[pidx].uint_32 = pidx + 1; + dd->arrayData()[pidx + 1].tag = Value::Undefined_Type; + dd->arrayData()[pidx + 1].uint_32 = static_cast<SparseArrayData *>(dd)->freeList(); + dd->arrayData()[pidx].tag = Value::Undefined_Type; + dd->arrayData()[pidx].uint_32 = pidx + 1; } else { - dd->data[pidx].tag = Value::Undefined_Type; - dd->data[pidx].uint_32 = static_cast<SparseArrayData *>(dd)->freeList; + dd->arrayData()[pidx].tag = Value::Undefined_Type; + dd->arrayData()[pidx].uint_32 = static_cast<SparseArrayData *>(dd)->freeList(); } - dd->freeList = pidx; - dd->sparse->erase(n); + dd->freeList() = pidx; + dd->sparse()->erase(n); return true; } void SparseArrayData::setAttribute(Object *o, uint index, PropertyAttributes attrs) { SparseArrayData *d = static_cast<SparseArrayData *>(o->arrayData()); - SparseArrayNode *n = d->sparse->insert(index); + SparseArrayNode *n = d->sparse()->insert(index); if (n->value == UINT_MAX) { n->value = allocate(o, attrs.isAccessor()); d = static_cast<SparseArrayData *>(o->arrayData()); } - else if (attrs.isAccessor() != d->attrs[n->value].isAccessor()) { + else if (attrs.isAccessor() != d->attrs()[n->value].isAccessor()) { // need to convert the slot free(d, n->value); n->value = allocate(o, attrs.isAccessor()); } - o->arrayData()->attrs[n->value] = attrs; + o->arrayData()->attrs()[n->value] = attrs; } PropertyAttributes SparseArrayData::attribute(const ArrayData *d, uint index) { - SparseArrayNode *n = static_cast<const SparseArrayData *>(d)->sparse->insert(index); + SparseArrayNode *n = static_cast<const SparseArrayData *>(d)->sparse()->insert(index); if (!n) return PropertyAttributes(); - return d->attrs[n->value]; + return d->attrs()[n->value]; } void SparseArrayData::push_front(Object *o, Value *values, uint n) { - Q_ASSERT(!o->arrayData()->attrs); + Q_ASSERT(!o->arrayData()->attrs()); for (int i = n - 1; i >= 0; --i) { uint idx = allocate(o); - o->arrayData()->data[idx] = values[i]; - static_cast<SparseArrayData *>(o->arrayData())->sparse->push_front(idx); + o->arrayData()->arrayData()[idx] = values[i]; + static_cast<SparseArrayData *>(o->arrayData())->sparse()->push_front(idx); } } ReturnedValue SparseArrayData::pop_front(Object *o) { - Q_ASSERT(!o->arrayData()->attrs); - uint idx = static_cast<SparseArrayData *>(o->arrayData())->sparse->pop_front(); + Q_ASSERT(!o->arrayData()->attrs()); + uint idx = static_cast<SparseArrayData *>(o->arrayData())->sparse()->pop_front(); ReturnedValue v; if (idx != UINT_MAX) { - v = o->arrayData()->data[idx].asReturnedValue(); + v = o->arrayData()->arrayData()[idx].asReturnedValue(); free(o->arrayData(), idx); } else { v = Encode::undefined(); @@ -526,12 +526,12 @@ ReturnedValue SparseArrayData::pop_front(Object *o) uint SparseArrayData::truncate(Object *o, uint newLen) { SparseArrayData *d = static_cast<SparseArrayData *>(o->arrayData()); - SparseArrayNode *begin = d->sparse->lowerBound(newLen); - if (begin != d->sparse->end()) { - SparseArrayNode *it = d->sparse->end()->previousNode(); + SparseArrayNode *begin = d->sparse()->lowerBound(newLen); + if (begin != d->sparse()->end()) { + SparseArrayNode *it = d->sparse()->end()->previousNode(); while (1) { - if (d->attrs) { - if (!d->attrs[it->value].isConfigurable()) { + if (d->attrs()) { + if (!d->attrs()[it->value].isConfigurable()) { newLen = it->key() + 1; break; } @@ -539,7 +539,7 @@ uint SparseArrayData::truncate(Object *o, uint newLen) free(d, it->value); bool brk = (it == begin); SparseArrayNode *prev = it->previousNode(); - static_cast<SparseArrayData *>(d)->sparse->erase(it); + static_cast<SparseArrayData *>(d)->sparse()->erase(it); if (brk) break; it = prev; @@ -551,9 +551,9 @@ uint SparseArrayData::truncate(Object *o, uint newLen) uint SparseArrayData::length(const ArrayData *d) { const SparseArrayData *dd = static_cast<const SparseArrayData *>(d); - if (!dd->sparse) + if (!dd->sparse()) return 0; - SparseArrayNode *n = dd->sparse->end(); + SparseArrayNode *n = dd->sparse()->end(); n = n->previousNode(); return n ? n->key() + 1 : 0; } @@ -586,18 +586,18 @@ uint ArrayData::append(Object *obj, const ArrayObject *otherObj, uint n) if (otherObj->hasAccessorProperty() && other->hasAttributes()) { Scope scope(obj->engine()); ScopedValue v(scope); - for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other)->sparse->begin(); - it != static_cast<const SparseArrayData *>(other)->sparse->end(); it = it->nextNode()) { - v = otherObj->getValue(reinterpret_cast<Property *>(other->data + it->value), other->attrs[it->value]); + for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other)->sparse()->begin(); + it != static_cast<const SparseArrayData *>(other)->sparse()->end(); it = it->nextNode()) { + v = otherObj->getValue(reinterpret_cast<Property *>(other->arrayData() + it->value), other->attrs()[it->value]); obj->arraySet(oldSize + it->key(), v); } } else { - for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other)->sparse->begin(); - it != static_cast<const SparseArrayData *>(other)->sparse->end(); it = it->nextNode()) - obj->arraySet(oldSize + it->key(), ValueRef(other->data[it->value])); + for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other)->sparse()->begin(); + it != static_cast<const SparseArrayData *>(other)->sparse()->end(); it = it->nextNode()) + obj->arraySet(oldSize + it->key(), ValueRef(other->arrayData()[it->value])); } } else { - obj->arrayPut(oldSize, other->data, n); + obj->arrayPut(oldSize, other->arrayData(), n); } return oldSize + n; @@ -605,28 +605,28 @@ uint ArrayData::append(Object *obj, const ArrayObject *otherObj, uint n) Property *ArrayData::insert(Object *o, uint index, bool isAccessor) { - if (!isAccessor && o->arrayData()->type != ArrayData::Sparse) { + if (!isAccessor && o->arrayData()->type() != ArrayData::Sparse) { SimpleArrayData *d = static_cast<SimpleArrayData *>(o->arrayData()); - if (index < 0x1000 || index < d->len + (d->len >> 2)) { - if (index >= o->arrayData()->alloc) { + if (index < 0x1000 || index < d->len() + (d->len() >> 2)) { + if (index >= o->arrayData()->alloc()) { o->arrayReserve(index + 1); d = static_cast<SimpleArrayData *>(o->arrayData()); } - if (index >= d->len) { + if (index >= d->len()) { // mark possible hole in the array - for (uint i = d->len; i < index; ++i) - d->data[i] = Primitive::emptyValue(); - d->len = index + 1; + for (uint i = d->len(); i < index; ++i) + d->arrayData()[i] = Primitive::emptyValue(); + d->len() = index + 1; } - return reinterpret_cast<Property *>(o->arrayData()->data + index); + return reinterpret_cast<Property *>(o->arrayData()->arrayData() + index); } } o->initSparseArray(); - SparseArrayNode *n = static_cast<SparseArrayData *>(o->arrayData())->sparse->insert(index); + SparseArrayNode *n = static_cast<SparseArrayData *>(o->arrayData())->sparse()->insert(index); if (n->value == UINT_MAX) n->value = SparseArrayData::allocate(o, isAccessor); - return reinterpret_cast<Property *>(o->arrayData()->data + n->value); + return reinterpret_cast<Property *>(o->arrayData()->arrayData() + n->value); } @@ -686,50 +686,50 @@ void ArrayData::sort(ExecutionContext *context, ObjectRef thisObject, const Valu // The spec says the sorting goes through a series of get,put and delete operations. // this implies that the attributes don't get sorted around. - if (thisObject->arrayData()->type == ArrayData::Sparse) { + if (thisObject->arrayData()->type() == ArrayData::Sparse) { // since we sort anyway, we can simply iterate over the entries in the sparse // array and append them one by one to a regular one. SparseArrayData *sparse = static_cast<SparseArrayData *>(thisObject->arrayData()); - if (!sparse->sparse->nEntries()) + if (!sparse->sparse()->nEntries()) return; thisObject->setArrayData(0); - ArrayData::realloc(thisObject, ArrayData::Simple, 0, sparse->sparse->nEntries(), sparse->attrs ? true : false); + ArrayData::realloc(thisObject, ArrayData::Simple, 0, sparse->sparse()->nEntries(), sparse->attrs() ? true : false); SimpleArrayData *d = static_cast<SimpleArrayData *>(thisObject->arrayData()); - SparseArrayNode *n = sparse->sparse->begin(); + SparseArrayNode *n = sparse->sparse()->begin(); uint i = 0; - if (sparse->attrs) { - while (n != sparse->sparse->end()) { + if (sparse->attrs()) { + while (n != sparse->sparse()->end()) { if (n->value >= len) break; - PropertyAttributes a = sparse->attrs ? sparse->attrs[n->value] : Attr_Data; - d->data[i] = thisObject->getValue(reinterpret_cast<Property *>(sparse->data + n->value), a); - d->attrs[i] = a.isAccessor() ? Attr_Data : a; + PropertyAttributes a = sparse->attrs() ? sparse->attrs()[n->value] : Attr_Data; + d->arrayData()[i] = thisObject->getValue(reinterpret_cast<Property *>(sparse->arrayData() + n->value), a); + d->attrs()[i] = a.isAccessor() ? Attr_Data : a; n = n->nextNode(); ++i; } } else { - while (n != sparse->sparse->end()) { + while (n != sparse->sparse()->end()) { if (n->value >= len) break; - d->data[i] = sparse->data[n->value]; + d->arrayData()[i] = sparse->arrayData()[n->value]; n = n->nextNode(); ++i; } } - d->len = i; + d->len() = i; if (len > i) len = i; - if (n != sparse->sparse->end()) { + if (n != sparse->sparse()->end()) { // have some entries outside the sort range that we need to ignore when sorting thisObject->initSparseArray(); - while (n != sparse->sparse->end()) { - PropertyAttributes a = sparse->attrs ? sparse->attrs[n->value] : Attr_Data; - thisObject->arraySet(n->value, *reinterpret_cast<Property *>(sparse->data + n->value), a); + while (n != sparse->sparse()->end()) { + PropertyAttributes a = sparse->attrs() ? sparse->attrs()[n->value] : Attr_Data; + thisObject->arraySet(n->value, *reinterpret_cast<Property *>(sparse->arrayData() + n->value), a); n = n->nextNode(); } @@ -738,18 +738,18 @@ void ArrayData::sort(ExecutionContext *context, ObjectRef thisObject, const Valu // ### explicitly delete sparse } else { SimpleArrayData *d = static_cast<SimpleArrayData *>(thisObject->arrayData()); - if (len > d->len) - len = d->len; + if (len > d->len()) + len = d->len(); // sort empty values to the end for (uint i = 0; i < len; i++) { - if (thisObject->arrayData()->data[i].isEmpty()) { + if (thisObject->arrayData()->arrayData()[i].isEmpty()) { while (--len > i) - if (!thisObject->arrayData()->data[len].isEmpty()) + if (!thisObject->arrayData()->arrayData()[len].isEmpty()) break; - Q_ASSERT(!thisObject->arrayData()->attrs || !thisObject->arrayData()->attrs[len].isAccessor()); - thisObject->arrayData()->data[i] = thisObject->arrayData()->data[len]; - thisObject->arrayData()->data[len] = Primitive::emptyValue(); + Q_ASSERT(!thisObject->arrayData()->attrs() || !thisObject->arrayData()->attrs()[len].isAccessor()); + thisObject->arrayData()->arrayData()[i] = thisObject->arrayData()->arrayData()[len]; + thisObject->arrayData()->arrayData()[len] = Primitive::emptyValue(); } } @@ -760,7 +760,7 @@ void ArrayData::sort(ExecutionContext *context, ObjectRef thisObject, const Valu ArrayElementLessThan lessThan(context, thisObject, comparefn); - Value *begin = thisObject->arrayData()->data; + Value *begin = thisObject->arrayData()->arrayData(); std::sort(begin, begin + len, lessThan); #ifdef CHECK_SPARSE_ARRAYS diff --git a/src/qml/jsruntime/qv4arraydata_p.h b/src/qml/jsruntime/qv4arraydata_p.h index eef3816ef6..a5524da4f9 100644 --- a/src/qml/jsruntime/qv4arraydata_p.h +++ b/src/qml/jsruntime/qv4arraydata_p.h @@ -92,13 +92,27 @@ struct Q_QML_EXPORT ArrayData : public Managed Custom = 3 }; - uint alloc; - Type type; - PropertyAttributes *attrs; - Value *data; + struct Data { + uint alloc; + Type type; + PropertyAttributes *attrs; + Value *arrayData; + }; + Data data; + + uint alloc() const { return data.alloc; } + uint &alloc() { return data.alloc; } + void setAlloc(uint a) { data.alloc = a; } + Type type() const { return data.type; } + void setType(Type t) { data.type = t; } + PropertyAttributes *attrs() const { return data.attrs; } + void setAttrs(PropertyAttributes *a) { data.attrs = a; } + Value *arrayData() const { return data.arrayData; } + Value *&arrayData() { return data.arrayData; } + void setArrayData(Value *v) { data.arrayData = v; } const ArrayVTable *vtable() const { return reinterpret_cast<const ArrayVTable *>(internalClass()->vtable); } - bool isSparse() const { return this && type == Sparse; } + bool isSparse() const { return this && type() == Sparse; } uint length() const { if (!this) @@ -107,11 +121,11 @@ struct Q_QML_EXPORT ArrayData : public Managed } bool hasAttributes() const { - return this && attrs; + return this && attrs(); } PropertyAttributes attributes(int i) const { Q_ASSERT(this); - return attrs ? vtable()->attribute(this, i) : Attr_Data; + return attrs() ? vtable()->attribute(this, i) : Attr_Data; } bool isEmpty(uint i) const { @@ -143,8 +157,16 @@ struct Q_QML_EXPORT SimpleArrayData : public ArrayData : ArrayData(engine->simpleArrayDataClass) {} - uint len; - uint offset; + struct Data { + uint len; + uint offset; + }; + Data data; + + uint &len() { return data.len; } + uint len() const { return data.len; } + uint &offset() { return data.offset; } + uint offset() const { return data.offset; } static void getHeadRoom(Object *o); static ArrayData *reallocate(Object *o, uint n, bool enforceAttributes); @@ -171,8 +193,16 @@ struct Q_QML_EXPORT SparseArrayData : public ArrayData : ArrayData(engine->emptyClass) { setVTable(staticVTable()); } - uint freeList; - SparseArray *sparse; + struct Data { + uint freeList; + SparseArray *sparse; + }; + Data data; + + uint &freeList() { return data.freeList; } + uint freeList() const { return data.freeList; } + SparseArray *sparse() const { return data.sparse; } + void setSparse(SparseArray *s) { data.sparse = s; } static uint allocate(Object *o, bool doubleSlot = false); static void free(ArrayData *d, uint idx); @@ -198,16 +228,16 @@ inline Property *ArrayData::getProperty(uint index) const { if (!this) return 0; - if (type != Sparse) { + if (type() != Sparse) { const SimpleArrayData *that = static_cast<const SimpleArrayData *>(this); - if (index >= that->len || data[index].isEmpty()) + if (index >= that->len() || arrayData()[index].isEmpty()) return 0; - return reinterpret_cast<Property *>(data + index); + return reinterpret_cast<Property *>(arrayData() + index); } else { - SparseArrayNode *n = static_cast<const SparseArrayData *>(this)->sparse->findNode(index); + SparseArrayNode *n = static_cast<const SparseArrayData *>(this)->sparse()->findNode(index); if (!n) return 0; - return reinterpret_cast<Property *>(data + n->value); + return reinterpret_cast<Property *>(arrayData() + n->value); } } diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp index 5c83eb0522..74712f9b3f 100644 --- a/src/qml/jsruntime/qv4arrayobject.cpp +++ b/src/qml/jsruntime/qv4arrayobject.cpp @@ -629,7 +629,7 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx) Q_ASSERT(instance->arrayType() == ArrayData::Simple || instance->arrayType() == ArrayData::Complex); if (len > instance->arrayData()->length()) len = instance->arrayData()->length(); - Value *val = instance->arrayData()->data; + Value *val = instance->arrayData()->arrayData(); Value *end = val + len; val += fromIndex; while (val < end) { @@ -638,7 +638,7 @@ ReturnedValue ArrayPrototype::method_indexOf(CallContext *ctx) if (scope.hasException()) return Encode::undefined(); if (RuntimeHelpers::strictEqual(value, searchValue)) - return Encode((uint)(val - instance->arrayData()->data)); + return Encode((uint)(val - instance->arrayData()->arrayData())); } ++val; } diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 916b37126b..ba73615cc2 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -309,7 +309,7 @@ ReturnedValue FunctionPrototype::method_apply(CallContext *ctx) } else { int alen = qMin(len, arr->arrayData()->length()); if (alen) - memcpy(callData->args, arr->arrayData()->data, alen*sizeof(Value)); + memcpy(callData->args, arr->arrayData()->arrayData(), alen*sizeof(Value)); for (quint32 i = alen; i < len; ++i) callData->args[i] = Primitive::undefinedValue(); } diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp index f43ef0b74e..4d56a7de98 100644 --- a/src/qml/jsruntime/qv4lookup.cpp +++ b/src/qml/jsruntime/qv4lookup.cpp @@ -171,10 +171,10 @@ ReturnedValue Lookup::indexedGetterObjectInt(Lookup *l, const ValueRef object, c return indexedGetterGeneric(l, object, index); Object *o = object->objectValue(); - if (o->arrayData() && o->arrayData()->type == ArrayData::Simple) { - if (idx < static_cast<SimpleArrayData *>(o->arrayData())->len) - if (!o->arrayData()->data[idx].isEmpty()) - return o->arrayData()->data[idx].asReturnedValue(); + if (o->arrayData() && o->arrayData()->type() == ArrayData::Simple) { + if (idx < static_cast<SimpleArrayData *>(o->arrayData())->len()) + if (!o->arrayData()->arrayData()[idx].isEmpty()) + return o->arrayData()->arrayData()[idx].asReturnedValue(); } return indexedGetterFallback(l, object, index); @@ -184,7 +184,7 @@ void Lookup::indexedSetterGeneric(Lookup *l, const ValueRef object, const ValueR { if (object->isObject()) { Object *o = object->objectValue(); - if (o->arrayData() && o->arrayData()->type == ArrayData::Simple && index->asArrayIndex() < UINT_MAX) { + if (o->arrayData() && o->arrayData()->type() == ArrayData::Simple && index->asArrayIndex() < UINT_MAX) { l->indexedSetter = indexedSetterObjectInt; indexedSetterObjectInt(l, object, index, v); return; @@ -203,10 +203,10 @@ void Lookup::indexedSetterFallback(Lookup *l, const ValueRef object, const Value uint idx = index->asArrayIndex(); if (idx < UINT_MAX) { - if (o->arrayData() && o->arrayData()->type == ArrayData::Simple) { + 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; + if (s && idx < s->len() && !s->arrayData()[idx].isEmpty()) { + s->arrayData()[idx] = value; return; } } @@ -227,10 +227,10 @@ void Lookup::indexedSetterObjectInt(Lookup *l, const ValueRef object, const Valu } Object *o = object->objectValue(); - if (o->arrayData() && o->arrayData()->type == ArrayData::Simple) { + 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; + if (idx < s->len() && !s->arrayData()[idx].isEmpty()) { + s->arrayData()[idx] = v; return; } } diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index d33e2941dc..354c6ceb0c 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -549,7 +549,7 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uin while (it->arrayNode != o->sparseEnd()) { int k = it->arrayNode->key(); uint pidx = it->arrayNode->value; - Property *p = reinterpret_cast<Property *>(o->arrayData()->data + pidx); + Property *p = reinterpret_cast<Property *>(o->arrayData()->arrayData() + pidx); it->arrayNode = it->arrayNode->nextNode(); PropertyAttributes a = o->arrayData()->attributes(k); if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) { @@ -565,7 +565,7 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, StringRef name, uin } // dense arrays while (it->arrayIndex < o->arrayData()->length()) { - Value *val = o->arrayData()->data + it->arrayIndex; + Value *val = o->arrayData()->arrayData() + it->arrayIndex; PropertyAttributes a = o->arrayData()->attributes(it->arrayIndex); ++it->arrayIndex; if (!val->isEmpty() @@ -1086,28 +1086,28 @@ void Object::copyArrayData(Object *other) } } else if (!other->arrayData()) { ; - } else if (other->hasAccessorProperty() && other->arrayData()->attrs && other->arrayData()->isSparse()){ + } else if (other->hasAccessorProperty() && other->arrayData()->attrs() && other->arrayData()->isSparse()){ // do it the slow way ScopedValue v(scope); - for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other->arrayData())->sparse->begin(); - it != static_cast<const SparseArrayData *>(other->arrayData())->sparse->end(); it = it->nextNode()) { - v = other->getValue(reinterpret_cast<Property *>(other->arrayData()->data + it->value), other->arrayData()->attrs[it->value]); + for (const SparseArrayNode *it = static_cast<const SparseArrayData *>(other->arrayData())->sparse()->begin(); + it != static_cast<const SparseArrayData *>(other->arrayData())->sparse()->end(); it = it->nextNode()) { + v = other->getValue(reinterpret_cast<Property *>(other->arrayData()->arrayData() + it->value), other->arrayData()->attrs()[it->value]); arraySet(it->key(), v); } } else { Q_ASSERT(!arrayData() && other->arrayData()); - ArrayData::realloc(this, other->arrayData()->type, 0, other->arrayData()->alloc, other->arrayData()->attrs); + ArrayData::realloc(this, other->arrayData()->type(), 0, other->arrayData()->alloc(), other->arrayData()->attrs()); if (other->arrayType() == ArrayData::Sparse) { SparseArrayData *od = static_cast<SparseArrayData *>(other->arrayData()); SparseArrayData *dd = static_cast<SparseArrayData *>(arrayData()); - dd->sparse = new SparseArray(*od->sparse); - dd->freeList = od->freeList; + dd->setSparse(new SparseArray(*od->sparse())); + dd->freeList() = od->freeList(); } else { SimpleArrayData *d = static_cast<SimpleArrayData *>(arrayData()); - d->len = static_cast<SimpleArrayData *>(other->arrayData())->len; - d->offset = 0; + d->len() = static_cast<SimpleArrayData *>(other->arrayData())->len(); + d->offset() = 0; } - memcpy(arrayData()->data, other->arrayData()->data, arrayData()->alloc*sizeof(Value)); + memcpy(arrayData()->arrayData(), other->arrayData()->arrayData(), arrayData()->alloc()*sizeof(Value)); } setArrayLengthUnchecked(other->getLength()); } diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index a3689d098a..1910737973 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -118,6 +118,7 @@ struct Q_QML_EXPORT Object: Managed { const Data *objectData() const { return &data; } Data *objectData() { return &data; } + Members &memberData() { return objectData()->memberData; } Members memberData() const { return objectData()->memberData; } const ArrayData *arrayData() const { return objectData()->arrayData; } ArrayData *arrayData() { return objectData()->arrayData; } @@ -210,7 +211,7 @@ public: } void setArrayAttributes(uint i, PropertyAttributes a) { Q_ASSERT(arrayData()); - if (arrayData()->attrs || a != Attr_Data) { + if (arrayData()->attrs() || a != Attr_Data) { ArrayData::ensureAttributes(this); a.resolve(); arrayData()->vtable()->setAttribute(this, i, a); @@ -220,13 +221,13 @@ public: void push_back(const ValueRef v); ArrayData::Type arrayType() const { - return arrayData() ? arrayData()->type : ArrayData::Simple; + return arrayData() ? arrayData()->type() : ArrayData::Simple; } // ### remove me void setArrayType(ArrayData::Type t) { Q_ASSERT(t != ArrayData::Simple && t != ArrayData::Sparse); arrayCreate(); - arrayData()->type = t; + arrayData()->setType(t); } inline void arrayReserve(uint n) { @@ -242,8 +243,8 @@ public: } void initSparseArray(); - SparseArrayNode *sparseBegin() { return arrayType() == ArrayData::Sparse ? static_cast<SparseArrayData *>(arrayData())->sparse->begin() : 0; } - SparseArrayNode *sparseEnd() { return arrayType() == ArrayData::Sparse ? static_cast<SparseArrayData *>(arrayData())->sparse->end() : 0; } + SparseArrayNode *sparseBegin() { return arrayType() == ArrayData::Sparse ? static_cast<SparseArrayData *>(arrayData())->sparse()->begin() : 0; } + SparseArrayNode *sparseEnd() { return arrayType() == ArrayData::Sparse ? static_cast<SparseArrayData *>(arrayData())->sparse()->end() : 0; } inline bool protoHasArray() { Scope scope(engine()); @@ -405,7 +406,7 @@ inline void Object::arraySet(uint index, const Property &p, PropertyAttributes a if (attributes.isAccessor()) { setHasAccessorProperty(); initSparseArray(); - } else if (index > 0x1000 && index > 2*arrayData()->alloc) { + } else if (index > 0x1000 && index > 2*arrayData()->alloc()) { initSparseArray(); } else { arrayData()->vtable()->reallocate(this, index + 1, false); @@ -423,7 +424,7 @@ inline void Object::arraySet(uint index, const Property &p, PropertyAttributes a inline void Object::arraySet(uint index, ValueRef value) { arrayCreate(); - if (index > 0x1000 && index > 2*arrayData()->alloc) { + if (index > 0x1000 && index > 2*arrayData()->alloc()) { initSparseArray(); } Property *pd = ArrayData::insert(this, index); diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index a8b107e9f2..9971289730 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -274,9 +274,9 @@ ReturnedValue ObjectPrototype::method_seal(CallContext *ctx) if (o->arrayData()) { ArrayData::ensureAttributes(o.getPointer()); - for (uint i = 0; i < o->arrayData()->alloc; ++i) { + for (uint i = 0; i < o->arrayData()->alloc(); ++i) { if (!o->arrayData()->isEmpty(i)) - o->arrayData()->attrs[i].setConfigurable(false); + o->arrayData()->attrs()[i].setConfigurable(false); } } @@ -299,11 +299,11 @@ ReturnedValue ObjectPrototype::method_freeze(CallContext *ctx) if (o->arrayData()) { ArrayData::ensureAttributes(o.getPointer()); - for (uint i = 0; i < o->arrayData()->alloc; ++i) { + for (uint i = 0; i < o->arrayData()->alloc(); ++i) { if (!o->arrayData()->isEmpty(i)) - o->arrayData()->attrs[i].setConfigurable(false); - if (o->arrayData()->attrs[i].isData()) - o->arrayData()->attrs[i].setWritable(false); + o->arrayData()->attrs()[i].setConfigurable(false); + if (o->arrayData()->attrs()[i].isData()) + o->arrayData()->attrs()[i].setWritable(false); } } return o.asReturnedValue(); @@ -336,10 +336,10 @@ ReturnedValue ObjectPrototype::method_isSealed(CallContext *ctx) if (!o->arrayData() || !o->arrayData()->length()) return Encode(true); - if (o->arrayData()->length() && !o->arrayData()->attrs) + if (o->arrayData()->length() && !o->arrayData()->attrs()) return Encode(false); - for (uint i = 0; i < o->arrayData()->alloc; ++i) { + for (uint i = 0; i < o->arrayData()->alloc(); ++i) { // ### Fix for sparse arrays if (!o->arrayData()->isEmpty(i)) if (o->arrayData()->attributes(i).isConfigurable()) @@ -365,10 +365,10 @@ ReturnedValue ObjectPrototype::method_isFrozen(CallContext *ctx) if (!o->arrayData()->length()) return Encode(true); - if (o->arrayData()->length() && !o->arrayData()->attrs) + if (o->arrayData()->length() && !o->arrayData()->attrs()) return Encode(false); - for (uint i = 0; i < o->arrayData()->alloc; ++i) { + for (uint i = 0; i < o->arrayData()->alloc(); ++i) { // ### Fix for sparse arrays if (!o->arrayData()->isEmpty(i)) if (o->arrayData()->attributes(i).isConfigurable() || o->arrayData()->attributes(i).isWritable()) diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 97d11eb48c..86eb0c7fe7 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -614,8 +614,8 @@ void Runtime::setElement(ExecutionContext *ctx, const ValueRef object, const Val if (idx < UINT_MAX) { if (o->arrayType() == ArrayData::Simple) { SimpleArrayData *s = static_cast<SimpleArrayData *>(o->arrayData()); - if (s && idx < s->len && !s->data[idx].isEmpty()) { - s->data[idx] = value; + if (s && idx < s->len() && !s->arrayData()[idx].isEmpty()) { + s->arrayData()[idx] = value; return; } } |