From eb2386a04260966c5d1f13941f7a10154e11625a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 11 Mar 2021 11:07:58 +0100 Subject: Optimize ExecutionEngine::metaTypeToJS() We almost never need to construct a QVariant to do this. Constructing a QVariant is excessively expensive if you have something simple like an integer. This also fixes the unexpected "unwrapping" of variants when we pass them through QJSValue. [ChangeLog][QtQml][Important Behavior Changes] If you create a QJSValue from a nested QVariant (that is, a QVariant containing another QVariant), then, when retrieving its contents again, the outer variant is not unwrapped anymore. Rather, you get exactly the value you've passed in. Change-Id: I8c16eed4f13e8cfdeced0756eef593b3b8e84dd1 Reviewed-by: Fabian Kosmale --- src/qml/jsruntime/qv4sequenceobject.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/qml/jsruntime/qv4sequenceobject.cpp') diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index 73fa2385fd..95ba210753 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -627,8 +627,14 @@ ReturnedValue SequencePrototype::newSequence(QV4::ExecutionEngine *engine, int s return Encode::undefined(); } -ReturnedValue SequencePrototype::fromVariant(QV4::ExecutionEngine *engine, const QVariant &v, - bool *succeeded) +ReturnedValue SequencePrototype::fromVariant( + QV4::ExecutionEngine *engine, const QVariant &v, bool *succeeded) +{ + return fromData(engine, v.metaType(), v.constData(), succeeded); +} + +ReturnedValue SequencePrototype::fromData( + ExecutionEngine *engine, const QMetaType &type, const void *data, bool *succeeded) { QV4::Scope scope(engine); // This function is called when assigning a sequence value to a normal JS var @@ -637,11 +643,10 @@ ReturnedValue SequencePrototype::fromVariant(QV4::ExecutionEngine *engine, const // QObject property. const QQmlType qmlType = QQmlMetaType::qmlType( - v.userType(), QQmlMetaType::TypeIdCategory::MetaType); + type.id(), QQmlMetaType::TypeIdCategory::MetaType); if (qmlType.isSequentialContainer()) { *succeeded = true; - QV4::ScopedObject obj(scope, engine->memoryManager->allocate( - qmlType, v.data())); + QV4::ScopedObject obj(scope, engine->memoryManager->allocate(qmlType, data)); return obj.asReturnedValue(); } -- cgit v1.2.3