Compile on Windows.
authorJan-Arve Saether <jan-arve.saether@nokia.com>
Wed, 18 Apr 2012 11:58:50 +0000 (13:58 +0200)
committerQt by Nokia <qt-info@nokia.com>
Sat, 21 Apr 2012 03:09:12 +0000 (05:09 +0200)
The previous code was trying to sum one pointer with one string
literal...
Using QVarLengthArray should also potentially speed things up a bit,
since it will avoid a malloc if className is small enough (less
than 15 bytes).

Change-Id: I41218babb3030e7e6f9c31fc77e4af1c209ae0a5
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
src/corelib/kernel/qmetatype.h

index 9377ddd..2261eb0 100644 (file)
@@ -45,6 +45,7 @@
 #include <QtCore/qglobal.h>
 #include <QtCore/qatomic.h>
 #include <QtCore/qbytearray.h>
+#include <QtCore/qvarlengtharray.h>
 #include <QtCore/qisenum.h>
 #ifndef QT_NO_QOBJECT
 #include <QtCore/qobjectdefs.h>
@@ -598,9 +599,14 @@ struct QMetaTypeIdQObject<T*, /* isPointerToTypeDerivedFromQObject */ true>
     static int qt_metatype_id()
     {
         static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
-        if (!metatype_id.load())
-            metatype_id.storeRelease(qRegisterMetaType<T*>(QByteArray(T::staticMetaObject.className() + QByteArray("*")).constData(),
+        if (!metatype_id.load()) {
+            int len = strlen(T::staticMetaObject.className());
+            QVarLengthArray<char, 16> classNameStar;
+            classNameStar.append(T::staticMetaObject.className(), len);
+            classNameStar.append("*\0", 2);
+            metatype_id.storeRelease(qRegisterMetaType<T*>(classNameStar.constData(),
                         reinterpret_cast<T**>(quintptr(-1))));
+        }
         return metatype_id.loadAcquire();
     }
 };