diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-10-20 17:19:25 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-11-07 09:00:48 +0000 |
commit | e72306a6f2aeb2bddbb462c205db8fad2fb5a1a4 (patch) | |
tree | 3b83e1cead58d97c2b055283487500472ca7d698 /src/qml/jsruntime/qv4jscall_p.h | |
parent | bc5ff76e5afe6356bebb344c9a5d8b304e852f3c (diff) |
Further cleanup JSCallData
Avoid allocations on the JS stack if possible
Change-Id: I344cd6dceb6264314f9d22c94db22b22d1d24d14
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4jscall_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4jscall_p.h | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h index 0f22aa1aa7..6d641bf9c5 100644 --- a/src/qml/jsruntime/qv4jscall_p.h +++ b/src/qml/jsruntime/qv4jscall_p.h @@ -62,42 +62,53 @@ namespace QV4 { struct JSCallData { JSCallData(const Scope &scope, int argc = 0, const Value *argv = 0, const Value *thisObject = 0) + : scope(scope), argc(argc) { - int size = int(offsetof(QV4::CallData, args)/sizeof(QV4::Value)) + argc; - ptr = reinterpret_cast<CallData *>(scope.engine->jsStackTop); - scope.engine->jsStackTop += size; - ptr->function = Encode::undefined(); - ptr->context = Encode::undefined(); - ptr->accumulator = Encode::undefined(); - ptr->thisObject = thisObject ? thisObject->asReturnedValue() : Encode::undefined(); - ptr->setArgc(argc); + if (thisObject) + this->thisObject = const_cast<Value *>(thisObject); + else + this->thisObject = scope.alloc(1); if (argv) - memcpy(ptr->args, argv, argc*sizeof(Value)); + this->args = const_cast<Value *>(argv); + else + this->args = scope.alloc(argc); } - CallData *operator->() const { - return ptr; + JSCallData *operator->() { + return this; } CallData *callData(const FunctionObject *f = nullptr) const { + int size = int(offsetof(QV4::CallData, args)/sizeof(QV4::Value)) + argc; + CallData *ptr = reinterpret_cast<CallData *>(scope.engine->jsStackTop); + scope.engine->jsStackTop += size; + ptr->function = Encode::undefined(); + ptr->context = Encode::undefined(); + ptr->accumulator = Encode::undefined(); + ptr->thisObject = thisObject->asReturnedValue(); + ptr->setArgc(argc); + if (argc) + memcpy(ptr->args, args, argc*sizeof(Value)); if (f) ptr->function = f->asReturnedValue(); return ptr; } - - CallData *ptr; + const Scope &scope; + int argc; + Value *args; + Value *thisObject; }; inline ReturnedValue FunctionObject::callAsConstructor(const JSCallData &data) const { - return d()->jsConstruct(this, data->args, data->argc()); + return d()->jsConstruct(this, data.args, data.argc); } inline ReturnedValue FunctionObject::call(const JSCallData &data) const { - return d()->jsCall(this, &data->thisObject, data->args, data->argc()); + return d()->jsCall(this, data.thisObject, data.args, data.argc); } |