aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4functionobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <[email protected]>2014-04-03 13:08:25 +0200
committerSimon Hausmann <[email protected]>2014-07-22 13:48:53 +0200
commitc2ef5bff232f758716f1665e5d9d9b9b2f20385d (patch)
tree281a2670200dc3bf804549131420dcaf89842cd0 /src/qml/jsruntime/qv4functionobject.cpp
parent4427576fe548b6f9f8acba6a5ac3082fbbb99724 (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 <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4functionobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp20
1 files changed, 12 insertions, 8 deletions
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);
}