diff options
author | Lars Knoll <lars.knoll@qt.io> | 2016-12-12 10:49:55 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2016-12-13 08:27:57 +0000 |
commit | 180decaf11ea6fb1147825a78a95c455400f7c7e (patch) | |
tree | b27564cfb0b2459cbc32f120471242ee108b5375 | |
parent | 4ccba8ea25312e0b635df21ce3fea7624744ee34 (diff) |
Optimize code in instanceOf() of FunctionObject::protoForConstructor()
Saves around 1.5% instructions for the Earley Boyer benchmark
Change-Id: I552d324d5e1713f655ab9909f30c9527bb4ff777
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 21 |
3 files changed, 17 insertions, 17 deletions
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 2da05f6217..64f7b98618 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -451,11 +451,10 @@ void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function Heap::Object *ScriptFunction::protoForConstructor() const { - Scope scope(engine()); - ScopedObject p(scope, protoProperty()); - if (p) - return p->d(); - return scope.engine->objectPrototype()->d(); + const Object *o = d()->protoProperty(); + if (o) + return o->d(); + return engine()->objectPrototype()->d(); } diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index c720632153..a02e89e883 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -79,6 +79,8 @@ struct Q_QML_PRIVATE_EXPORT FunctionObject : Object { unsigned int varCount() { return function ? function->compiledFunction->nLocals : 0; } bool needsActivation() const { return function ? function->needsActivation() : false; } + const QV4::Object *protoProperty() const { return propertyData(Index_Prototype)->cast<QV4::Object>(); } + Pointer<ExecutionContext> scope; Function *function; }; @@ -145,8 +147,6 @@ struct Q_QML_EXPORT FunctionObject: Object { static Heap::FunctionObject *createScriptFunction(ExecutionContext *scope, Function *function); - ReturnedValue protoProperty() const { return propertyData(Heap::FunctionObject::Index_Prototype)->asReturnedValue(); } - bool needsActivation() const { return d()->needsActivation(); } bool strictMode() const { return d()->function ? d()->function->isStrict() : false; } bool isBinding() const; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index b71bd4146a..57ad181030 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -345,28 +345,29 @@ ReturnedValue Runtime::method_deleteName(ExecutionEngine *engine, int nameIndex) QV4::ReturnedValue Runtime::method_instanceof(ExecutionEngine *engine, const Value &left, const Value &right) { - Scope scope(engine); - ScopedFunctionObject f(scope, right.as<FunctionObject>()); - if (!f) + const FunctionObject *function = right.as<FunctionObject>(); + if (!function) return engine->throwTypeError(); - if (f->isBoundFunction()) - f = static_cast<BoundFunction *>(f.getPointer())->target(); + Heap::FunctionObject *f = function->d(); + if (function->isBoundFunction()) + f = function->cast<BoundFunction>()->target(); - ScopedObject v(scope, left.as<Object>()); - if (!v) + const Object *o = left.as<Object>(); + if (!o) return Encode(false); + Heap::Object *v = o->d(); - ScopedObject o(scope, f->protoProperty()); + o = f->protoProperty(); if (!o) return engine->throwTypeError(); while (v) { - v = v->prototype(); + v = v->prototype; if (!v) break; - else if (o->d() == v->d()) + else if (o->d() == v) return Encode(true); } |