diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-08-25 16:52:45 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-09-15 19:12:47 +0000 |
commit | 64c3e1cbb100f7cd67c2d79b4b92a2e873e8163d (patch) | |
tree | 88026e3f982fea034c11bbe56516ba092ea3e5de /src/qml/jsruntime/qv4object.cpp | |
parent | fb52dab6b41ddd6955cb14e1474f90ee5333dac9 (diff) |
Cleanups
There's only one place where we need to resize our member
data, namely when we call setInternalClass() on an object.
In addition, encapsulate the access to the memberdata better
in preparation for inline property data later on.
Change-Id: Ia34d0253d5d1792f1d7c4981556d78375fa7a755
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime/qv4object.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 1cb544d205..2cdc8bd1ee 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -52,16 +52,21 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(Object); Heap::Object::Object(InternalClass *internalClass, QV4::Object *prototype) - : internalClass(internalClass), - prototype(prototype ? prototype->d() : 0) + : prototype(prototype ? prototype->d() : 0) { - if (internalClass->size) { + if (internalClass) { Scope scope(internalClass->engine); ScopedObject o(scope, this); - o->ensureMemberIndex(internalClass->engine, internalClass->size); + o->setInternalClass(internalClass); } } +void Object::setInternalClass(InternalClass *ic) +{ + d()->internalClass = ic; + ensureMemberData(); +} + bool Object::setPrototype(Object *proto) { Heap::Object *pp = proto ? proto->d() : 0; @@ -197,9 +202,10 @@ void Object::markObjects(Heap::Base *that, ExecutionEngine *e) o->prototype->mark(e); } -void Object::ensureMemberIndex(uint idx) +void Object::ensureMemberData() { - d()->memberData = MemberData::reallocate(engine(), d()->memberData, idx); + QV4::InternalClass *ic = internalClass(); + d()->memberData = MemberData::reallocate(ic->engine, d()->memberData, ic->size); } void Object::insertMember(String *s, const Property *p, PropertyAttributes attributes) @@ -207,9 +213,6 @@ void Object::insertMember(String *s, const Property *p, PropertyAttributes attri uint idx; InternalClass::addMember(this, s, attributes, &idx); - - ensureMemberIndex(internalClass()->size); - if (attributes.isAccessor()) { Property *pp = propertyAt(idx); pp->value = p->value; @@ -475,7 +478,7 @@ void Object::setLookup(Managed *m, Lookup *l, const Value &value) l->classList[0] = o->internalClass(); l->index = idx; l->setter = Lookup::setter0; - o->memberData()->data[idx] = value; + *o->propertyData(idx) = value; return; } @@ -1162,7 +1165,7 @@ ReturnedValue ArrayObject::getLookup(const Managed *m, Lookup *l) // special case, as the property is on the object itself l->getter = Lookup::arrayLengthGetter; const ArrayObject *a = static_cast<const ArrayObject *>(m); - return a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].asReturnedValue(); + return a->propertyData(Heap::ArrayObject::LengthPropertyIndex)->asReturnedValue(); } return Object::getLookup(m, l); } @@ -1170,9 +1173,9 @@ ReturnedValue ArrayObject::getLookup(const Managed *m, Lookup *l) uint ArrayObject::getLength(const Managed *m) { const ArrayObject *a = static_cast<const ArrayObject *>(m); - if (a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].isInteger()) - return a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].integerValue(); - return Primitive::toUInt32(a->memberData()->data[Heap::ArrayObject::LengthPropertyIndex].doubleValue()); + if (a->propertyData(Heap::ArrayObject::LengthPropertyIndex)->isInteger()) + return a->propertyData(Heap::ArrayObject::LengthPropertyIndex)->integerValue(); + return Primitive::toUInt32(a->propertyData(Heap::ArrayObject::LengthPropertyIndex)->doubleValue()); } QStringList ArrayObject::toQStringList() const |