diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-04-03 13:08:25 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-07-22 13:48:53 +0200 |
commit | c2ef5bff232f758716f1665e5d9d9b9b2f20385d (patch) | |
tree | 281a2670200dc3bf804549131420dcaf89842cd0 /src/qml/jsruntime | |
parent | 4427576fe548b6f9f8acba6a5ac3082fbbb99724 (diff) |
Use Members for storing the bound arguments in BoundFunction
Cleans up the code, and allows us to remove the destructor
for bound function objects.
Change-Id: Id32ac69171f7975ec7679d07d25c0eb6b4ca6fb5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 20 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4memberdata_p.h | 1 |
5 files changed, 18 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 52a89eba51..d1ed6566a9 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -487,7 +487,7 @@ Returned<FunctionObject> *ExecutionEngine::newBuiltinFunction(ExecutionContext * return f->asReturned<FunctionObject>(); } -Returned<BoundFunction> *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<Value> &boundArgs) +Returned<BoundFunction> *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const Members &boundArgs) { Q_ASSERT(target); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index d678d6595e..a7808edd9b 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -86,6 +86,7 @@ struct SyntaxErrorObject; struct ArgumentsObject; struct ExecutionContext; struct ExecutionEngine; +struct Members; class MemoryManager; class ExecutableAllocator; @@ -307,7 +308,7 @@ public: ExecutionContext *popContext(); Returned<FunctionObject> *newBuiltinFunction(ExecutionContext *scope, const StringRef name, ReturnedValue (*code)(CallContext *)); - Returned<BoundFunction> *newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<Value> &boundArgs); + Returned<BoundFunction> *newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QV4::Members &boundArgs); Returned<Object> *newObject(); Returned<Object> *newObject(InternalClass *internalClass); diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 1c6de05ff1..f00df25354 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -341,9 +341,14 @@ ReturnedValue FunctionPrototype::method_bind(CallContext *ctx) return ctx->throwTypeError(); ScopedValue boundThis(scope, ctx->argument(0)); - QVector<Value> boundArgs; - for (int i = 1; i < ctx->callData->argc; ++i) - boundArgs += ctx->callData->args[i]; + Members boundArgs; + boundArgs.reset(); + if (ctx->callData->argc > 1) { + boundArgs.ensureIndex(scope.engine, ctx->callData->argc - 1); + boundArgs.d()->size = ctx->callData->argc - 1; + memcpy(boundArgs.data(), ctx->callData->args + 1, (ctx->callData->argc - 1)*sizeof(Value)); + } + ScopedValue protectBoundArgs(scope, boundArgs.d()); return ctx->engine->newBoundFunction(ctx->engine->rootContext, target, boundThis, boundArgs)->asReturnedValue(); } @@ -601,7 +606,7 @@ DEFINE_OBJECT_VTABLE_NO_DESTROY(IndexedBuiltinFunction); DEFINE_OBJECT_VTABLE(BoundFunction); -BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<Value> &boundArgs) +BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const Members &boundArgs) : FunctionObject(scope, QStringLiteral("__bound function__")) , target(target) , boundArgs(boundArgs) @@ -641,7 +646,7 @@ ReturnedValue BoundFunction::call(Managed *that, CallData *dd) ScopedCallData callData(scope, f->boundArgs.size() + dd->argc); callData->thisObject = f->boundThis; - memcpy(callData->args, f->boundArgs.constData(), f->boundArgs.size()*sizeof(Value)); + memcpy(callData->args, f->boundArgs.data(), f->boundArgs.size()*sizeof(Value)); memcpy(callData->args + f->boundArgs.size(), dd->args, dd->argc*sizeof(Value)); return f->target->call(callData); } @@ -654,7 +659,7 @@ ReturnedValue BoundFunction::construct(Managed *that, CallData *dd) return Encode::undefined(); ScopedCallData callData(scope, f->boundArgs.size() + dd->argc); - memcpy(callData->args, f->boundArgs.constData(), f->boundArgs.size()*sizeof(Value)); + memcpy(callData->args, f->boundArgs.data(), f->boundArgs.size()*sizeof(Value)); memcpy(callData->args + f->boundArgs.size(), dd->args, dd->argc*sizeof(Value)); return f->target->construct(callData); } @@ -664,7 +669,6 @@ void BoundFunction::markObjects(Managed *that, ExecutionEngine *e) BoundFunction *o = static_cast<BoundFunction *>(that); o->target->mark(e); o->boundThis.mark(e); - for (int i = 0; i < o->boundArgs.size(); ++i) - o->boundArgs.at(i).mark(e); + o->boundArgs.mark(e); FunctionObject::markObjects(that, e); } diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 76a69d7d2a..ef58ffce7f 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -229,9 +229,9 @@ struct BoundFunction: FunctionObject { V4_OBJECT FunctionObject *target; Value boundThis; - QVector<Value> boundArgs; + Members boundArgs; - BoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<Value> &boundArgs); + BoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const Members &boundArgs); ~BoundFunction() {} diff --git a/src/qml/jsruntime/qv4memberdata_p.h b/src/qml/jsruntime/qv4memberdata_p.h index 03aa75a365..e0f632b1ed 100644 --- a/src/qml/jsruntime/qv4memberdata_p.h +++ b/src/qml/jsruntime/qv4memberdata_p.h @@ -62,6 +62,7 @@ struct MemberData : Managed struct Members : Value { + void reset() { m = 0; } void ensureIndex(QV4::ExecutionEngine *e, uint idx); Value &operator[] (uint idx) const { return static_cast<MemberData *>(managed())->data[idx]; } inline uint size() const { return d() ? d()->size : 0; } |