diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2023-01-30 16:37:37 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-02-24 09:42:23 +0100 |
| commit | a09ea6b3d6265a98c17e190db007fecfbd76f317 (patch) | |
| tree | 5886c0877aa7b3b33e7685a2c043390be73e9a23 /src/qml/jsruntime/qv4engine.cpp | |
| parent | 499acf3114c973c5387331cab36a0b7038423cfd (diff) | |
Avoid duplicate value type creation
We can actually produce an uninitialized but pre-allocated QVariant
using QVariant::Private. Using the new in-place construction support in
QMetaObject, we can minimize the amount of copying necessary for value
types.
Fixes: QTBUG-108789
Change-Id: I6b748794a6adbf6558e1e3086eab80fcfb3154a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 56cc4efb48..41c7a90906 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1569,9 +1569,9 @@ static QVariant toVariant( QV4::ScopedValue arrayValue(scope); for (qint64 i = 0; i < length; ++i) { arrayValue = a->get(i); - QVariant asVariant(valueMetaType); - if (QQmlValueTypeProvider::createValueType( - arrayValue, valueMetaType, asVariant.data())) { + QVariant asVariant = QQmlValueTypeProvider::createValueType( + arrayValue, valueMetaType); + if (asVariant.isValid()) { retnAsIterable.metaContainer().addValue(retn.data(), asVariant.constData()); continue; } @@ -1662,8 +1662,8 @@ static QVariant toVariant( #endif if (metaType.isValid() && !(metaType.flags() & QMetaType::PointerToQObject)) { - QVariant result(metaType); - if (QQmlValueTypeProvider::createValueType(value, metaType, result.data())) + const QVariant result = QQmlValueTypeProvider::createValueType(value, metaType); + if (result.isValid()) return result; } |
