From 9f4cfec74517f7ff3f65037ad04abac33e2104ba Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 8 Dec 2016 21:01:51 +0100 Subject: Avoid some copies of Values on the JS stack Change-Id: I1c7dca6e8d17da9f3d76b68d072370b087840f2b Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 18 ++++++++---------- src/qml/jsruntime/qv4functionobject_p.h | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 02ea763b30..66549ffd3e 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -216,8 +216,7 @@ Heap::FunctionObject *FunctionObject::createQmlFunction(QQmlContextData *qmlCont runtimeFunction->updateInternalClass(engine, signalParameters); } - QV4::ScopedFunctionObject function(valueScope, QV4::FunctionObject::createScriptFunction(wrapperContext, runtimeFunction)); - return function->d(); + return QV4::FunctionObject::createScriptFunction(wrapperContext, runtimeFunction); } @@ -344,11 +343,11 @@ ReturnedValue FunctionPrototype::method_toString(CallContext *ctx) ReturnedValue FunctionPrototype::method_apply(CallContext *ctx) { - Scope scope(ctx); - ScopedFunctionObject o(scope, ctx->thisObject().as()); + FunctionObject *o = ctx->thisObject().as(); if (!o) return ctx->engine()->throwTypeError(); + Scope scope(ctx); ScopedValue arg(scope, ctx->argument(1)); ScopedObject arr(scope, arg); @@ -387,12 +386,11 @@ ReturnedValue FunctionPrototype::method_apply(CallContext *ctx) ReturnedValue FunctionPrototype::method_call(CallContext *ctx) { - Scope scope(ctx); - - ScopedFunctionObject o(scope, ctx->thisObject().as()); + FunctionObject *o = ctx->thisObject().as(); if (!o) return ctx->engine()->throwTypeError(); + Scope scope(ctx); ScopedCallData callData(scope, ctx->argc() ? ctx->argc() - 1 : 0); if (ctx->argc()) { for (int i = 1; i < ctx->argc(); ++i) @@ -406,11 +404,11 @@ ReturnedValue FunctionPrototype::method_call(CallContext *ctx) ReturnedValue FunctionPrototype::method_bind(CallContext *ctx) { - Scope scope(ctx); - ScopedFunctionObject target(scope, ctx->thisObject()); + FunctionObject *target = ctx->thisObject().as(); if (!target) return ctx->engine()->throwTypeError(); + Scope scope(ctx); ScopedValue boundThis(scope, ctx->argument(0)); Scoped boundArgs(scope, (Heap::MemberData *)0); if (ctx->argc() > 1) { @@ -601,7 +599,7 @@ void SimpleScriptFunction::call(const Managed *that, Scope &scope, CallData *cal QQmlPropertyCapture::registerQmlDependencies(f->function()->compiledFunction, scope); } -Heap::Object *SimpleScriptFunction::protoForConstructor() +Heap::Object *SimpleScriptFunction::protoForConstructor() const { Scope scope(engine()); ScopedObject p(scope, protoProperty()); diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 3dcc7ab482..5c176b88b4 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -154,7 +154,7 @@ struct Q_QML_EXPORT FunctionObject: Object { static Heap::FunctionObject *createQmlFunction(QQmlContextData *qmlContext, QObject *scopeObject, QV4::Function *runtimeFunction, const QList &signalParameters = QList(), QString *error = 0); - ReturnedValue protoProperty() { return propertyData(Heap::FunctionObject::Index_Prototype)->asReturnedValue(); } + 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; } @@ -232,7 +232,7 @@ struct SimpleScriptFunction: FunctionObject { static void construct(const Managed *, Scope &scope, CallData *callData); static void call(const Managed *that, Scope &scope, CallData *callData); - Heap::Object *protoForConstructor(); + Heap::Object *protoForConstructor() const; }; struct ScriptFunction: SimpleScriptFunction { -- cgit v1.2.3