From a09ea6b3d6265a98c17e190db007fecfbd76f317 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 30 Jan 2023 16:37:37 +0100 Subject: 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 --- src/qml/jsruntime/qv4engine.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/qml/jsruntime/qv4engine.cpp') 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; } -- cgit v1.2.3