Don't use scopes in the instanceOf operator
authorLars Knoll <lars.knoll@digia.com>
Wed, 26 Mar 2014 07:55:28 +0000 (08:55 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 27 Mar 2014 19:39:59 +0000 (20:39 +0100)
There's no need to use scopes here, as instanceof can't
trigger any calls into the memorymanager. This slightly
speeds up the code.

Change-Id: Ie7f5c8f3982df1e24d21cfc4e0841d479a75c664
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4runtime.cpp

index c1c764195b1f63df83c9285936828279d693cd3b..c46f3990dc537ea44bf7d4551952475c87ce4661 100644 (file)
@@ -300,6 +300,9 @@ ReturnedValue Runtime::deleteName(ExecutionContext *ctx, const StringRef name)
 
 QV4::ReturnedValue Runtime::instanceof(ExecutionContext *ctx, const ValueRef left, const ValueRef right)
 {
+    // As nothing in this method can call into the memory manager, avoid using a Scope
+    // for performance reasons
+
     FunctionObject *f = right->asFunctionObject();
     if (!f)
         return ctx->throwTypeError();
@@ -307,23 +310,20 @@ QV4::ReturnedValue Runtime::instanceof(ExecutionContext *ctx, const ValueRef lef
     if (f->subtype == FunctionObject::BoundFunction)
         f = static_cast<BoundFunction *>(f)->target;
 
-    Scope scope(ctx->engine);
-    ScopedObject v(scope, left);
+    Object *v = left->asObject();
     if (!v)
         return Encode(false);
 
-    Scoped<Object> o(scope, f->protoProperty());
-    if (!o) {
-        scope.engine->currentContext()->throwTypeError();
-        return Encode(false);
-    }
+    Object *o = QV4::Value::fromReturnedValue(f->protoProperty()).asObject();
+    if (!o)
+        return ctx->throwTypeError();
 
     while (v) {
         v = v->prototype();
 
-        if (! v)
+        if (!v)
             break;
-        else if (o.getPointer() == v)
+        else if (o == v)
             return Encode(true);
     }