aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlproperty.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-01-30 16:37:37 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-02-24 09:42:23 +0100
commita09ea6b3d6265a98c17e190db007fecfbd76f317 (patch)
tree5886c0877aa7b3b33e7685a2c043390be73e9a23 /src/qml/qml/qqmlproperty.cpp
parent499acf3114c973c5387331cab36a0b7038423cfd (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/qml/qqmlproperty.cpp')
-rw-r--r--src/qml/qml/qqmlproperty.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 306f733e21..3c039ba55d 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1423,14 +1423,15 @@ static ConvertAndAssignResult tryConvertAndAssign(
}
}
- QVariant converted(propertyMetaType);
- if (QQmlValueTypeProvider::createValueType(value, propertyMetaType, converted.data())
- || QMetaType::convert(value.metaType(), value.constData(),
- propertyMetaType, converted.data())) {
- return {true, property.writeProperty(object, converted.data(), flags)};
+ QVariant converted = QQmlValueTypeProvider::createValueType(value, propertyMetaType);
+ if (!converted.isValid()) {
+ converted = QVariant(propertyMetaType);
+ if (!QMetaType::convert(value.metaType(), value.constData(),
+ propertyMetaType, converted.data())) {
+ return {false, false};
+ }
}
-
- return {false, false};
+ return {true, property.writeProperty(object, converted.data(), flags)};
};
template<typename Op>