diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-24 18:01:16 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-29 09:04:13 +0100 |
commit | b82ae347397595241dcd4a5848ad0c6bfae4574b (patch) | |
tree | 045bea2be5ac6c88ccf498537913e200a4e627d6 /src/qml/jsruntime/qv4jscall_p.h | |
parent | bd294e78239a198c9c7458a490681d170823a97f (diff) |
Avoid needless construction and destruction of return values
In most cases the AOT compiled function will successfully placement-new
the return value. Therefore, we can provide uninitialized space. Only do
the construct/destruct dance in the cases when it's already slow.
Change-Id: Ia339774fde03e459f290f167ddadd1c47a644b8e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4jscall_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4jscall_p.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h index de4acca8a3..3f0c8ee06d 100644 --- a/src/qml/jsruntime/qv4jscall_p.h +++ b/src/qml/jsruntime/qv4jscall_p.h @@ -184,7 +184,6 @@ ReturnedValue convertAndCall( types[0] = aotFunction->returnType; if (const qsizetype returnSize = types[0].sizeOf()) { Q_ALLOCA_ASSIGN(void, returnValue, returnSize); - types[0].construct(returnValue); values[0] = returnValue; } else { values[0] = nullptr; @@ -227,15 +226,16 @@ void convertAndCall(ExecutionEngine *engine, const Value *thisObject, const QMetaType resultType = types[0]; if (scope.hasException()) { // Clear the return value - resultType.destruct(result); - resultType.construct(result, nullptr); + resultType.construct(result); } else { // When the return type is QVariant, JS objects are to be returned as // QJSValue wrapped in QVariant. metaTypeFromJS unwraps them, unfortunately. - if (resultType == QMetaType::fromType<QVariant>()) - *static_cast<QVariant *>(result) = scope.engine->toVariant(jsResult, QMetaType {}); - else + if (resultType == QMetaType::fromType<QVariant>()) { + new (result) QVariant(scope.engine->toVariant(jsResult, QMetaType {})); + } else { + resultType.construct(result); scope.engine->metaTypeFromJS(jsResult, resultType, result); + } } } |