From 99783cd6dec326058b8db345145b1f8f71cfb6f0 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 5 Aug 2017 00:15:44 +0200 Subject: Completely avoid intermediate scopes for simple functions Change-Id: I1fe2ff987e79cf590ad5ad3fc520b17925f8b616 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4context.cpp | 31 ++++++++++++++++--------------- src/qml/jsruntime/qv4context_p.h | 4 ++-- src/qml/jsruntime/qv4functionobject.cpp | 12 ++++++------ src/qml/jsruntime/qv4script.cpp | 4 ++-- 4 files changed, 26 insertions(+), 25 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 4053eb4f09..22278e0405 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -232,47 +232,48 @@ bool ExecutionContext::deleteProperty(String *name) } // Do a standard call with this execution context as the outer scope -ReturnedValue ExecutionContext::call(Scope &scope, CallData *callData, Function *function, const FunctionObject *f) +ReturnedValue ExecutionContext::call(ExecutionEngine *engine, CallData *callData, Function *function, const FunctionObject *f) { - ExecutionContextSaver ctxSaver(scope.engine); + Scope scope(engine); + ExecutionContextSaver ctxSaver(engine); Scoped ctx(scope, newCallContext(function, callData)); if (f) - ctx->d()->function.set(scope.engine, f->d()); - scope.engine->pushContext(ctx); + ctx->d()->function.set(engine, f->d()); + engine->pushContext(ctx); - ReturnedValue res = Q_V4_PROFILE(scope.engine, function); + ReturnedValue res = Q_V4_PROFILE(engine, function); if (function->hasQmlDependencies) - QQmlPropertyCapture::registerQmlDependencies(scope.engine, function->compiledFunction); + QQmlPropertyCapture::registerQmlDependencies(engine, function->compiledFunction); return res; } // Do a simple, fast call with this execution context as the outer scope -ReturnedValue QV4::ExecutionContext::simpleCall(Scope &scope, CallData *callData, Function *function) +ReturnedValue QV4::ExecutionContext::simpleCall(ExecutionEngine *engine, CallData *callData, Function *function) { Q_ASSERT(function->canUseSimpleFunction()); - ExecutionContextSaver ctxSaver(scope.engine); + ExecutionContextSaver ctxSaver(engine); - CallContext::Data *ctx = scope.engine->memoryManager->allocSimpleCallContext(); + CallContext::Data *ctx = engine->memoryManager->allocSimpleCallContext(); ctx->strictMode = function->isStrict(); ctx->callData = callData; ctx->v4Function = function; - ctx->outer.set(scope.engine, this->d()); + ctx->outer.set(engine, this->d()); for (int i = callData->argc; i < (int)function->nFormals; ++i) callData->args[i] = Encode::undefined(); - scope.engine->pushContext(ctx); - Q_ASSERT(scope.engine->current == ctx); + engine->pushContext(ctx); + Q_ASSERT(engine->current == ctx); - ReturnedValue res = Q_V4_PROFILE(scope.engine, function); + ReturnedValue res = Q_V4_PROFILE(engine, function); if (function->hasQmlDependencies) - QQmlPropertyCapture::registerQmlDependencies(scope.engine, function->compiledFunction); - scope.engine->memoryManager->freeSimpleCallContext(); + QQmlPropertyCapture::registerQmlDependencies(engine, function->compiledFunction); + engine->memoryManager->freeSimpleCallContext(); return res; } diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index bb8f9b13fa..0945087de2 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -223,8 +223,8 @@ struct Q_QML_EXPORT ExecutionContext : public Managed return d()->callData->argument(i); } - ReturnedValue call(Scope &scope, CallData *callData, QV4::Function *function, const QV4::FunctionObject *f = 0); - ReturnedValue simpleCall(Scope &scope, CallData *callData, QV4::Function *function); + ReturnedValue call(ExecutionEngine *engine, CallData *callData, QV4::Function *function, const QV4::FunctionObject *f = 0); + ReturnedValue simpleCall(ExecutionEngine *engine, CallData *callData, QV4::Function *function); }; struct Q_QML_EXPORT CallContext : public ExecutionContext diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index f09772115c..10118ea403 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -372,9 +372,9 @@ ReturnedValue ScriptFunction::construct(const Managed *that, CallData *callData) ScopedContext c(scope, f->scope()); ScopedValue result(scope); if (v4Function->canUseSimpleCall) - result = c->simpleCall(scope, callData, v4Function); + result = c->simpleCall(scope.engine, callData, v4Function); else - result = c->call(scope, callData, v4Function, f); + result = c->call(scope.engine, callData, v4Function, f); if (Q_UNLIKELY(v4->hasException)) return Encode::undefined(); @@ -394,12 +394,12 @@ ReturnedValue ScriptFunction::call(const Managed *that, CallData *callData) QV4::Function *v4Function = f->function(); Q_ASSERT(v4Function); - Scope scope(v4); - ScopedContext c(scope, f->scope()); + Value s = Value::fromHeapObject(f->scope()); + ExecutionContext *outer = static_cast(&s); if (v4Function->canUseSimpleCall) - return c->simpleCall(scope, callData, v4Function); + return outer->simpleCall(v4, callData, v4Function); else - return c->call(scope, callData, v4Function, f); + return outer->call(v4, callData, v4Function, f); } void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function) diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index b771978def..2b97a0f1d4 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -159,9 +159,9 @@ ReturnedValue Script::run() ScopedCallData callData(valueScope); callData->thisObject = Primitive::undefinedValue(); if (vmFunction->canUseSimpleFunction()) - return qml->simpleCall(valueScope, callData, vmFunction); + return qml->simpleCall(valueScope.engine, callData, vmFunction); else - return qml->call(valueScope, callData, vmFunction); + return qml->call(valueScope.engine, callData, vmFunction); } } -- cgit v1.2.3