aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4sequenceobject.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-03-11 11:07:58 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-03-13 10:08:48 +0100
commiteb2386a04260966c5d1f13941f7a10154e11625a (patch)
tree2bbe824419230c62de6d88f255f45819c757a62b /src/qml/jsruntime/qv4sequenceobject.cpp
parenta9c93e2716a097c637515aded49a3308e257204b (diff)
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4sequenceobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp15
1 files changed, 10 insertions, 5 deletions
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<QV4Sequence>(
- qmlType, v.data()));
+ QV4::ScopedObject obj(scope, engine->memoryManager->allocate<QV4Sequence>(qmlType, data));
return obj.asReturnedValue();
}