QMetaTypeId: optimize qt_metatype_id() in special cases

Same change as for Q_DECLARE_METATYPE, but in the container and
smart pointer specialisations of it.

Change-Id: If9390ccc43eb3b07122f5ea5b8094139b5e1ded0
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2012-08-24 12:40:20 +02:00 committed by Qt by Nokia
parent 56603a8d83
commit 3de60970e5

View File

@ -648,16 +648,17 @@ struct QMetaTypeIdQObject<T*, /* isPointerToTypeDerivedFromQObject */ true>
static int qt_metatype_id()
{
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0);
if (!metatype_id.load()) {
if (const int id = metatype_id.loadAcquire())
return id;
const int len = int(strlen(T::staticMetaObject.className()));
QVarLengthArray<char, 16> classNameStar;
classNameStar.append(T::staticMetaObject.className(), len);
classNameStar.append('*');
metatype_id.storeRelease(qRegisterNormalizedMetaType<T*>( \
const int newId = qRegisterNormalizedMetaType<T*>( \
QByteArray(classNameStar.constData(), classNameStar.size()),
reinterpret_cast<T**>(quintptr(-1))));
}
return metatype_id.loadAcquire();
reinterpret_cast<T**>(quintptr(-1)));
metatype_id.storeRelease(newId);
return newId;
}
};
@ -733,7 +734,8 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id.load()) { \
if (const int id = metatype_id.load()) \
return id; \
QVarLengthArray<char, 24> name; \
name.append(#SINGLE_ARG_TEMPLATE, int(sizeof(#SINGLE_ARG_TEMPLATE)) - 1); \
name.append('<'); \
@ -743,12 +745,11 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
if (name.last() == '>') \
name.append(' '); \
name.append('>'); \
metatype_id.storeRelease( \
qRegisterNormalizedMetaType< SINGLE_ARG_TEMPLATE<T> >( \
const int newId = qRegisterNormalizedMetaType< SINGLE_ARG_TEMPLATE<T> >( \
QByteArray(name.constData(), name.size()), \
reinterpret_cast< SINGLE_ARG_TEMPLATE<T> *>(quintptr(-1)))); \
} \
return metatype_id.loadAcquire(); \
reinterpret_cast< SINGLE_ARG_TEMPLATE<T> *>(quintptr(-1))); \
metatype_id.storeRelease(newId); \
return newId; \
} \
};
@ -762,7 +763,8 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id.load()) {\
if (const int id = metatype_id.loadAcquire()) \
return id; \
QVarLengthArray<char, 24> name; \
name.append(#DOUBLE_ARG_TEMPLATE, sizeof(#DOUBLE_ARG_TEMPLATE) - 1); \
name.append('<'); \
@ -776,12 +778,11 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
if (name.last() == '>') \
name.append(' '); \
name.append('>'); \
metatype_id.storeRelease(\
qRegisterNormalizedMetaType< DOUBLE_ARG_TEMPLATE<T, U> >(\
const int newId = qRegisterNormalizedMetaType< DOUBLE_ARG_TEMPLATE<T, U> >(\
QByteArray(name.constData(), name.size()), \
reinterpret_cast< DOUBLE_ARG_TEMPLATE<T, U> *>(quintptr(-1)))); \
}\
return metatype_id.loadAcquire(); \
reinterpret_cast< DOUBLE_ARG_TEMPLATE<T, U> *>(quintptr(-1))); \
metatype_id.storeRelease(newId); \
return newId; \
} \
};
@ -803,11 +804,12 @@ struct QMetaTypeId_ ## SMART_POINTER ## _QObjectStar<T, true> \
static int qt_metatype_id() \
{ \
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
if (!metatype_id.load()) { \
metatype_id.storeRelease(qRegisterNormalizedMetaType< SMART_POINTER<T> >( #SMART_POINTER "<" + QByteArray(T::staticMetaObject.className()) + ">", \
reinterpret_cast< SMART_POINTER<T> *>(quintptr(-1)))); \
} \
return metatype_id.loadAcquire(); \
if (const int id = metatype_id.loadAcquire()) \
return id; \
const int newId = qRegisterNormalizedMetaType< SMART_POINTER<T> >( #SMART_POINTER "<" + QByteArray(T::staticMetaObject.className()) + ">", \
reinterpret_cast< SMART_POINTER<T> *>(quintptr(-1))); \
metatype_id.storeRelease(newId); \
return newId; \
} \
}; \
\