Avoid recreating QVariantLists when extracted from a QVariant
authorJocelyn Turcotte <jturcotte@woboq.com>
Mon, 10 Aug 2015 19:39:04 +0000 (21:39 +0200)
committerJocelyn Turcotte (Woboq GmbH) <jturcotte@woboq.com>
Mon, 24 Aug 2015 21:03:24 +0000 (21:03 +0000)
Wrapping a QVariantList in a QVariant to pass it to QML would
trigger a deep copy each time QML would try to access elements
in the list (specifically in QQmlListAccessor::at).

This reverts a part of 8c4deff51c8064f5a15cae0342bfa66b6663662b
by specifying the associative array conversions explicitly without
including the current type in the list of types to convert through
an iteration.

Task-number: QTBUG-41403
Change-Id: If9fddfe6d36f789ac4aa61a7c32677cd1dd077d8
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
src/corelib/kernel/qmetatype.h
src/corelib/kernel/qvariant.h

index 9e3e1e94faf46e7f0155f949e0a75a532d89fc1d..b7f01ca5cae892bf95480d1da2a5b78f2aea03a7 100644 (file)
@@ -2244,21 +2244,6 @@ namespace QtPrivate {
     };
 }
 
-namespace QtMetaTypePrivate {
-inline Q_DECL_CONSTEXPR bool isBuiltinSequentialType(int typeId)
-{
-    return typeId == qMetaTypeId<QStringList>()
-            || typeId == qMetaTypeId<QByteArrayList>()
-            || typeId == qMetaTypeId<QVariantList>();
-}
-
-inline Q_DECL_CONSTEXPR bool isBuiltinAssociativeType(int typeId)
-{
-    return typeId == qMetaTypeId<QVariantHash>()
-            || typeId == qMetaTypeId<QVariantMap>();
-}
-} // QtMetaTypePrivate
-
 QT_END_NAMESPACE
 
 #endif // QMETATYPE_H
index 27b19982de2fe36cee4d4be85b91c55adf72f1e1..4c7e4982807c86472eb79bda88154ca07a3c70ab 100644 (file)
@@ -750,7 +750,7 @@ namespace QtPrivate {
         static QVariantList invoke(const QVariant &v)
         {
             const int typeId = v.userType();
-            if (QtMetaTypePrivate::isBuiltinSequentialType(typeId) || QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QSequentialIterableImpl>())) {
+            if (typeId == qMetaTypeId<QStringList>() || typeId == qMetaTypeId<QByteArrayList>() || QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QSequentialIterableImpl>())) {
                 QSequentialIterable iter = QVariantValueHelperInterface<QSequentialIterable>::invoke(v);
                 QVariantList l;
                 l.reserve(iter.size());
@@ -767,7 +767,7 @@ namespace QtPrivate {
         static QVariantHash invoke(const QVariant &v)
         {
             const int typeId = v.userType();
-            if (QtMetaTypePrivate::isBuiltinAssociativeType(typeId) || QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QAssociativeIterableImpl>())) {
+            if (typeId == qMetaTypeId<QVariantMap>() || QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QAssociativeIterableImpl>())) {
                 QAssociativeIterable iter = QVariantValueHelperInterface<QAssociativeIterable>::invoke(v);
                 QVariantHash l;
                 l.reserve(iter.size());
@@ -784,7 +784,7 @@ namespace QtPrivate {
         static QVariantMap invoke(const QVariant &v)
         {
             const int typeId = v.userType();
-            if (QtMetaTypePrivate::isBuiltinAssociativeType(typeId) || QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QAssociativeIterableImpl>())) {
+            if (typeId == qMetaTypeId<QVariantHash>() || QMetaType::hasRegisteredConverterFunction(typeId, qMetaTypeId<QtMetaTypePrivate::QAssociativeIterableImpl>())) {
                 QAssociativeIterable iter = QVariantValueHelperInterface<QAssociativeIterable>::invoke(v);
                 QVariantMap l;
                 for (QAssociativeIterable::const_iterator it = iter.begin(), end = iter.end(); it != end; ++it)