Some optimisations for QV4::Script
authorLars Knoll <lars.knoll@digia.com>
Tue, 25 Jun 2013 09:00:31 +0000 (11:00 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Jun 2013 12:55:44 +0000 (14:55 +0200)
Change-Id: I468288a537a1a2fa4c38eb188c7b026a390fe13d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/v4/qv4script.cpp

index a2277a2..8c60194 100644 (file)
@@ -69,6 +69,9 @@ struct QmlBindingWrapper : FunctionObject
         usesArgumentsObject = function->usesArgumentsObject;
         needsActivation = function->needsActivation();
         defineReadonlyProperty(scope->engine->id_length, Value::fromInt32(1));
+
+        qmlContext = scope->engine->newQmlContext(this, qml);
+        scope->engine->popContext();
     }
 
     static Value call(Managed *that, const Value &, Value *, int);
@@ -78,6 +81,7 @@ struct QmlBindingWrapper : FunctionObject
         if (wrapper->qml)
             wrapper->qml->mark();
         FunctionObject::markObjects(m);
+        wrapper->qmlContext->mark();
     }
 
 protected:
@@ -85,6 +89,8 @@ protected:
 
 private:
     Object *qml;
+    CallContext *qmlContext;
+
 };
 
 DEFINE_MANAGED_VTABLE(QmlBindingWrapper);
@@ -94,10 +100,10 @@ Value QmlBindingWrapper::call(Managed *that, const Value &, Value *, int)
     ExecutionEngine *engine = that->engine();
     QmlBindingWrapper *This = static_cast<QmlBindingWrapper *>(that);
 
-    ExecutionContext *qmlScope = engine->newQmlContext(This, This->qml);
-
-    Value result = This->function->code(qmlScope, This->function->codeData);
-
+    CallContext *ctx = This->qmlContext;
+    std::fill(ctx->locals, ctx->locals + ctx->function->varCount, Value::undefinedValue());
+    engine->pushContext(ctx);
+    Value result = This->function->code(ctx, This->function->codeData);
     engine->popContext();
 
     return result;
@@ -107,6 +113,9 @@ Value QmlBindingWrapper::call(Managed *that, const Value &, Value *, int)
 
 void Script::parse()
 {
+    if (parsed)
+        return;
+
     using namespace QQmlJS;
 
     parsed = true;