From 689caa14fc527a7e3c85403c963bec7451c6c1db Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 17 Nov 2014 20:55:41 +0100 Subject: [PATCH] Remove arrayData() calls from qv4object.cpp Change-Id: I92c74e87918a5f958ff17f4cbbc1888b58833fc6 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4object.cpp | 45 ++++++++++++++++++++++------------------- src/qml/jsruntime/qv4object_p.h | 14 ++++++------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 755f699..1160e2c 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -346,6 +346,7 @@ bool Object::hasOwnProperty(uint index) const { if (arrayData() && !arrayData()->isEmpty(index)) return true; + if (isStringObject()) { String *s = static_cast(this)->d()->value.asString(); if (index < (uint)s->d()->length()) @@ -403,7 +404,7 @@ PropertyAttributes Object::query(const Managed *m, String *name) PropertyAttributes Object::queryIndexed(const Managed *m, uint index) { const Object *o = static_cast(m); - if (o->arrayData() && o->arrayData()->get(index) != Primitive::emptyValue().asReturnedValue()) + if (o->arrayData() && !o->arrayData()->isEmpty(index)) return o->arrayData()->attributes(index); if (o->isStringObject()) { @@ -522,10 +523,10 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, String *&name, uint while (it->arrayNode != o->sparseEnd()) { int k = it->arrayNode->key(); uint pidx = it->arrayNode->value; - SparseArrayData *sa = static_cast(o->arrayData()); - Property *p = reinterpret_cast(sa->arrayData() + pidx); + Heap::SparseArrayData *sa = static_cast(o->d()->arrayData); + Property *p = reinterpret_cast(sa->arrayData + pidx); it->arrayNode = it->arrayNode->nextNode(); - PropertyAttributes a = o->arrayData()->attributes(k); + PropertyAttributes a = sa->attrs ? sa->attrs[pidx] : Attr_Data; if (!(it->flags & ObjectIterator::EnumerableOnly) || a.isEnumerable()) { it->arrayIndex = k + 1; *index = k; @@ -538,8 +539,8 @@ void Object::advanceIterator(Managed *m, ObjectIterator *it, String *&name, uint it->arrayIndex = UINT_MAX; } // dense arrays - while (it->arrayIndex < o->arrayData()->length()) { - SimpleArrayData *sa = static_cast(o->arrayData()); + while (it->arrayIndex < o->d()->arrayData->len) { + Heap::SimpleArrayData *sa = static_cast(o->d()->arrayData); Value &val = sa->data(it->arrayIndex); PropertyAttributes a = o->arrayData()->attributes(it->arrayIndex); ++it->arrayIndex; @@ -817,10 +818,12 @@ bool Object::internalDeleteProperty(String *name) bool Object::internalDeleteIndexedProperty(uint index) { - if (internalClass()->engine->hasException) + Scope scope(engine()); + if (scope.engine->hasException) return false; - if (!arrayData() || arrayData()->vtable()->del(this, index)) + Scoped ad(scope, arrayData()); + if (!ad || ad->vtable()->del(this, index)) return true; if (engine()->currentContext()->d()->strictMode) @@ -1063,28 +1066,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->d()->arrayData->attrs && other->d()->arrayData->isSparse()){ // do it the slow way ScopedValue v(scope); - SparseArrayData *osa = static_cast(other->arrayData()); - for (const SparseArrayNode *it = osa->sparse()->begin(); it != osa->sparse()->end(); it = it->nextNode()) { - v = other->getValue(reinterpret_cast(osa->arrayData() + it->value), other->arrayData()->attrs()[it->value]); + Heap::ArrayData *osa = other->d()->arrayData; + for (const SparseArrayNode *it = osa->sparse->begin(); it != osa->sparse->end(); it = it->nextNode()) { + v = other->getValue(reinterpret_cast(osa->arrayData + it->value), osa->attrs[it->value]); arraySet(it->key(), v); } } else { Q_ASSERT(!arrayData() && other->arrayData()); - ArrayData::realloc(this, other->arrayData()->type(), other->arrayData()->alloc(), false); + ArrayData::realloc(this, other->d()->arrayData->type, other->d()->arrayData->alloc, false); if (other->arrayType() == Heap::ArrayData::Sparse) { - SparseArrayData *od = static_cast(other->arrayData()); - SparseArrayData *dd = static_cast(arrayData()); - dd->setSparse(new SparseArray(*od->sparse())); - dd->freeList() = od->freeList(); + Heap::ArrayData *od = other->d()->arrayData; + Heap::ArrayData *dd = d()->arrayData; + dd->sparse = new SparseArray(*od->sparse); + dd->freeList = od->freeList; } else { - SimpleArrayData *d = static_cast(arrayData()); - d->len() = static_cast(other->arrayData())->len(); - d->d()->offset = static_cast(other->arrayData())->d()->offset; + Heap::ArrayData *dd = d()->arrayData; + dd->len = other->d()->arrayData->len; + dd->offset = other->d()->arrayData->offset; } - memcpy(arrayData()->d()->arrayData, other->arrayData()->d()->arrayData, arrayData()->alloc()*sizeof(Value)); + memcpy(d()->arrayData->arrayData, other->d()->arrayData->arrayData, d()->arrayData->alloc*sizeof(Value)); } setArrayLengthUnchecked(other->getLength()); } diff --git a/src/qml/jsruntime/qv4object_p.h b/src/qml/jsruntime/qv4object_p.h index 2e2d433..2fd0901 100644 --- a/src/qml/jsruntime/qv4object_p.h +++ b/src/qml/jsruntime/qv4object_p.h @@ -191,7 +191,7 @@ public: } void setArrayAttributes(uint i, PropertyAttributes a) { Q_ASSERT(arrayData()); - if (arrayData()->attrs() || a != Attr_Data) { + if (d()->arrayData->attrs || a != Attr_Data) { ArrayData::ensureAttributes(this); a.resolve(); arrayData()->vtable()->setAttribute(this, i, a); @@ -201,13 +201,13 @@ public: void push_back(const ValueRef v); ArrayData::Type arrayType() const { - return arrayData() ? arrayData()->type() : Heap::ArrayData::Simple; + return arrayData() ? d()->arrayData->type : Heap::ArrayData::Simple; } // ### remove me void setArrayType(ArrayData::Type t) { Q_ASSERT(t != Heap::ArrayData::Simple && t != Heap::ArrayData::Sparse); arrayCreate(); - arrayData()->setType(t); + d()->arrayData->type = t; } inline void arrayReserve(uint n) { @@ -223,8 +223,8 @@ public: } void initSparseArray(); - SparseArrayNode *sparseBegin() { return arrayType() == Heap::ArrayData::Sparse ? static_cast(arrayData())->sparse()->begin() : 0; } - SparseArrayNode *sparseEnd() { return arrayType() == Heap::ArrayData::Sparse ? static_cast(arrayData())->sparse()->end() : 0; } + SparseArrayNode *sparseBegin() { return arrayType() == Heap::ArrayData::Sparse ? d()->arrayData->sparse->begin() : 0; } + SparseArrayNode *sparseEnd() { return arrayType() == Heap::ArrayData::Sparse ? d()->arrayData->sparse->end() : 0; } inline bool protoHasArray() { Scope scope(engine()); @@ -359,7 +359,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*d()->arrayData->alloc) { initSparseArray(); } else { arrayData()->vtable()->reallocate(this, index + 1, false); @@ -377,7 +377,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*d()->arrayData->alloc) { initSparseArray(); } Property *pd = ArrayData::insert(this, index); -- 2.7.4