Use static-less QMetaType API in QVariant.
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>
Mon, 9 Jan 2012 10:36:03 +0000 (11:36 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 16 Feb 2012 01:00:30 +0000 (02:00 +0100)
This patch improves performance when constructing a custom type in
a QVariant by ~ 7-20% (instructions count) depending on the type size
and metatype attributes.

Change-Id: Ic2707ff5abd689b66e23c1794f111504bf9b3b01
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
src/corelib/kernel/qvariant.cpp
tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp

index 4197fe9..d0470ff 100644 (file)
@@ -787,7 +787,8 @@ const QVariant::Handler qt_dummy_variant_handler = {
 
 static void customConstruct(QVariant::Private *d, const void *copy)
 {
-    const uint size = QMetaType::sizeOf(d->type);
+    const QMetaType type(d->type);
+    const uint size = type.sizeOf();
     if (!size) {
         d->type = QVariant::Invalid;
         return;
@@ -795,11 +796,11 @@ static void customConstruct(QVariant::Private *d, const void *copy)
 
     // this logic should match with QVariantIntegrator::CanUseInternalSpace
     if (size <= sizeof(QVariant::Private::Data)
-            && (QMetaType::typeFlags(d->type) & QMetaType::MovableType)) {
-        QMetaType::construct(d->type, &d->data.ptr, copy);
+            && (type.flags() & QMetaType::MovableType)) {
+        type.construct(&d->data.ptr, copy);
         d->is_shared = false;
     } else {
-        void *ptr = QMetaType::create(d->type, copy);
+        void *ptr = type.create(copy);
         d->is_shared = true;
         d->data.shared = new QVariant::PrivateShared(ptr);
     }
index e842e18..f6b4d88 100644 (file)
@@ -90,6 +90,7 @@ struct BigClass
     double n,i,e,r,o,b;
 };
 Q_STATIC_ASSERT(sizeof(BigClass) > sizeof(QVariant::Private::Data));
+Q_DECLARE_TYPEINFO(BigClass, Q_MOVABLE_TYPE);
 Q_DECLARE_METATYPE(BigClass);
 
 struct SmallClass
@@ -97,6 +98,7 @@ struct SmallClass
     char s;
 };
 Q_STATIC_ASSERT(sizeof(SmallClass) <= sizeof(QVariant::Private::Data));
+Q_DECLARE_TYPEINFO(SmallClass, Q_MOVABLE_TYPE);
 Q_DECLARE_METATYPE(SmallClass);
 
 void tst_qvariant::testBound()