summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-11 12:09:33 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-11 21:33:22 +0000
commit49c9a5fbdbb14f87876de2e44b2783239ff2fdff (patch)
treefa72e3191f76db6d487fb77471822691c4acb353
parentedb2cdc06ac5ab808429c654c55de87c8c4bf450 (diff)
Add a shortcut into Object::internalPut() for the common casev5.12.0-alpha1
This avoids a lot of the slowdown of the more generic code path. Change-Id: I1a22f55900d3dc829d7733f9d79b8de5d79dc44c Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
-rw-r--r--src/qml/jsruntime/qv4object.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp
index c1f6642c9d..ec6675adc0 100644
--- a/src/qml/jsruntime/qv4object.cpp
+++ b/src/qml/jsruntime/qv4object.cpp
@@ -464,6 +464,49 @@ bool Object::internalPut(PropertyKey id, const Value &value, Value *receiver)
if (scope.engine->hasException)
return false;
+ Object *r = receiver->objectValue();
+ if (r && r->d() == d()) {
+ // receiver and this object are the same
+ if (d()->internalClass->vtable->getOwnProperty == Object::virtualGetOwnProperty) {
+ // This object standard methods in the vtable, so we can take a shortcut
+ // and avoid the calls to getOwnProperty and defineOwnProperty
+ uint index = id.asArrayIndex();
+
+ PropertyAttributes attrs;
+ PropertyIndex propertyIndex{nullptr, nullptr};
+
+ if (index != UINT_MAX) {
+ if (arrayData())
+ propertyIndex = arrayData()->getValueOrSetter(index, &attrs);
+ } else {
+ uint member = internalClass()->find(id);
+ if (member < UINT_MAX) {
+ attrs = internalClass()->propertyData[member];
+ propertyIndex = d()->writablePropertyData(attrs.isAccessor() ? member + SetterOffset : member);
+ }
+ }
+
+ if (!propertyIndex.isNull() && !attrs.isAccessor()) {
+ if (!attrs.isWritable())
+ return false;
+ else if (isArrayObject() && id == scope.engine->id_length()->propertyKey()) {
+ bool ok;
+ uint l = value.asArrayLength(&ok);
+ if (!ok) {
+ scope.engine->throwRangeError(value);
+ return false;
+ }
+ ok = setArrayLength(l);
+ if (!ok)
+ return false;
+ } else {
+ propertyIndex.set(scope.engine, value);
+ }
+ return true;
+ }
+ }
+ }
+
ScopedProperty p(scope);
PropertyAttributes attrs;
attrs = getOwnProperty(id, p);
@@ -488,7 +531,6 @@ bool Object::internalPut(PropertyKey id, const Value &value, Value *receiver)
// Data property
if (!attrs.isWritable())
return false;
- Object *r = receiver->objectValue();
if (!r)
return false;
attrs = r->getOwnProperty(id, p);