diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-09-12 20:08:54 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-09-16 17:00:26 +0000 |
commit | cd148a1fd4959daac669581df35f91104fab7b8b (patch) | |
tree | 4c14c558a00614edfdc240d0dc156a1cc20bfd3f /src/qml/jsruntime/qv4object.cpp | |
parent | e436fb3569603bca8ad0a71fef67c03d2920aedc (diff) |
Optimize Object::virtualGet()
Optimize virtualGet() for the common case where the proto chain
are all regular objects.
Change-Id: I51eea9a4b96033be4effc2072fedc5b9b08e8440
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4object.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index ec6675adc0..e58b9d8168 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -94,7 +94,7 @@ void Heap::Object::setUsedAsProto() internalClass.set(internalClass->engine, internalClass->asProtoClass()); } -ReturnedValue Object::getValue(const Value &thisObject, const Value &v, PropertyAttributes attrs) +ReturnedValue Object::getValueAccessor(const Value &thisObject, const Value &v, PropertyAttributes attrs) { if (!attrs.isAccessor()) return v.asReturnedValue(); @@ -413,41 +413,50 @@ OwnPropertyKeyIterator *Object::virtualOwnPropertyKeys(const Object *o, Value *t // Section 8.12.3 ReturnedValue Object::internalGet(PropertyKey id, const Value *receiver, bool *hasProperty) const { + Heap::Object *o = d(); + uint index = id.asArrayIndex(); if (index != UINT_MAX) { Scope scope(this); PropertyAttributes attrs; - ScopedObject o(scope, this); ScopedProperty pd(scope); - if (o->arrayData() && o->arrayData()->getProperty(index, pd, &attrs)) { - if (hasProperty) - *hasProperty = true; - return Object::getValue(*receiver, pd->value, attrs); - } - if (o->isStringObject()) { - ScopedString str(scope, static_cast<StringObject *>(o.getPointer())->getIndex(index)); - if (str) { - attrs = (Attr_NotWritable|Attr_NotConfigurable); + while (1) { + if (o->arrayData && o->arrayData->getProperty(index, pd, &attrs)) { if (hasProperty) *hasProperty = true; - return str.asReturnedValue(); + return Object::getValue(*receiver, pd->value, attrs); + } + if (o->internalClass->vtable->type == Type_StringObject) { + ScopedString str(scope, static_cast<Heap::StringObject *>(o)->getIndex(index)); + if (str) { + attrs = (Attr_NotWritable|Attr_NotConfigurable); + if (hasProperty) + *hasProperty = true; + return str.asReturnedValue(); + } } + o = o->prototype(); + if (!o || o->internalClass->vtable->get != Object::virtualGet) + break; } } else { - Heap::Object *o = d(); Q_ASSERT(!id.isArrayIndex()); - uint idx = o->internalClass->find(id); - if (idx < UINT_MAX) { - if (hasProperty) - *hasProperty = true; - return Object::getValue(*receiver, *o->propertyData(idx), o->internalClass->propertyData.at(idx)); + while (1) { + uint idx = o->internalClass->find(id); + if (idx < UINT_MAX) { + if (hasProperty) + *hasProperty = true; + return Object::getValue(*receiver, *o->propertyData(idx), o->internalClass->propertyData.at(idx)); + } + o = o->prototype(); + if (!o || o->internalClass->vtable->get != Object::virtualGet) + break; } } - Heap::Object *p = d()->prototype(); - if (p) { - const Value v = Primitive::fromHeapObject(p); + if (o) { + const Value v = Primitive::fromHeapObject(o); const Object &obj = static_cast<const Object &>(v); return obj.get(id, receiver, hasProperty); } |