Change-Id: I0fbd713fcdf094f9d13acee855b6dd6986695e0d
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
class QCustomTypeInfo : public QMetaTypeInterface
{
public:
class QCustomTypeInfo : public QMetaTypeInterface
{
public:
+ QCustomTypeInfo()
+ : alias(-1)
+ {
+ QMetaTypeInterface empty = QT_METATYPE_INTERFACE_INIT(void);
+ *static_cast<QMetaTypeInterface*>(this) = empty;
+ }
QByteArray typeName;
int alias;
};
QByteArray typeName;
int alias;
};
static void Destroy(const int type, void *where)
{
if (QTypeModuleInfo<T>::IsGui) {
static void Destroy(const int type, void *where)
{
if (QTypeModuleInfo<T>::IsGui) {
- if (qMetaTypeGuiHelper)
+ if (Q_LIKELY(qMetaTypeGuiHelper))
qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where);
return;
}
if (QTypeModuleInfo<T>::IsWidget) {
qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].deleter(where);
return;
}
if (QTypeModuleInfo<T>::IsWidget) {
- if (qMetaTypeWidgetsHelper)
+ if (Q_LIKELY(qMetaTypeWidgetsHelper))
qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where);
return;
}
qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].deleter(where);
return;
}
return;
deleter = ct->at(type - QMetaType::User).deleter;
}
return;
deleter = ct->at(type - QMetaType::User).deleter;
}
- if (Q_LIKELY(deleter))
- deleter(where);
struct ConstructorImpl<T, /* IsAcceptedType = */ false> {
static void *Construct(const int type, void *where, const T *copy)
{
struct ConstructorImpl<T, /* IsAcceptedType = */ false> {
static void *Construct(const int type, void *where, const T *copy)
{
- QMetaType::Constructor ctor = 0;
- if (QTypeModuleInfo<T>::IsGui) {
- if (!qMetaTypeGuiHelper)
- return 0;
- ctor = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor;
- } else if (QTypeModuleInfo<T>::IsWidget) {
- if (!qMetaTypeWidgetsHelper)
- return 0;
- ctor = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor;
- } else
- return customTypeConstructor(type, where, copy);
-
- return ctor(where, copy);
+ if (QTypeModuleInfo<T>::IsGui)
+ return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].constructor(where, copy) : 0;
+
+ if (QTypeModuleInfo<T>::IsWidget)
+ return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].constructor(where, copy) : 0;
+
+ // This point can be reached only for known types that definition is not available, for example
+ // in bootstrap mode. We have no other choice then ignore it.
+ return 0;
private:
static void *customTypeConstructor(const int type, void *where, const void *copy)
{
private:
static void *customTypeConstructor(const int type, void *where, const void *copy)
{
- QMetaType::Constructor ctor = 0;
+ QMetaType::Constructor ctor;
const QVector<QCustomTypeInfo> * const ct = customTypes();
{
QReadLocker locker(customTypesLock());
const QVector<QCustomTypeInfo> * const ct = customTypes();
{
QReadLocker locker(customTypesLock());
- if (type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)
+ if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User))
return 0;
ctor = ct->at(type - QMetaType::User).constructor;
}
return 0;
ctor = ct->at(type - QMetaType::User).constructor;
}
- return ctor ? ctor(where, copy) : 0;
+ return ctor(where, copy);
struct DestructorImpl<T, /* IsAcceptedType = */ false> {
static void Destruct(const int type, void *where)
{
struct DestructorImpl<T, /* IsAcceptedType = */ false> {
static void Destruct(const int type, void *where)
{
- QMetaType::Destructor dtor = 0;
if (QTypeModuleInfo<T>::IsGui) {
if (QTypeModuleInfo<T>::IsGui) {
- if (!qMetaTypeGuiHelper)
- return;
- dtor = qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor;
- } else if (QTypeModuleInfo<T>::IsWidget) {
- if (!qMetaTypeWidgetsHelper)
- return;
- dtor = qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor;
- } else {
- customTypeDestructor(type, where);
+ if (Q_LIKELY(qMetaTypeGuiHelper))
+ qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].destructor(where);
+ return;
+ }
+ if (QTypeModuleInfo<T>::IsWidget) {
+ if (Q_LIKELY(qMetaTypeWidgetsHelper))
+ qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].destructor(where);
+ // This point can be reached only for known types that definition is not available, for example
+ // in bootstrap mode. We have no other choice then ignore it.
private:
static void customTypeDestructor(const int type, void *where)
{
private:
static void customTypeDestructor(const int type, void *where)
{
- QMetaType::Destructor dtor = 0;
+ QMetaType::Destructor dtor;
const QVector<QCustomTypeInfo> * const ct = customTypes();
{
QReadLocker locker(customTypesLock());
const QVector<QCustomTypeInfo> * const ct = customTypes();
{
QReadLocker locker(customTypesLock());
- if (type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)
+ if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User))
return;
dtor = ct->at(type - QMetaType::User).destructor;
}
return;
dtor = ct->at(type - QMetaType::User).destructor;
}
struct SizeOfImpl<T, /* IsAcceptedType = */ false> {
static int Size(const int type)
{
struct SizeOfImpl<T, /* IsAcceptedType = */ false> {
static int Size(const int type)
{
- if (QTypeModuleInfo<T>::IsGui) {
- if (!qMetaTypeGuiHelper)
- return 0;
- return qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size;
- } else if (QTypeModuleInfo<T>::IsWidget) {
- if (!qMetaTypeWidgetsHelper)
- return 0;
- return qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size;
- }
- return customTypeSizeOf(type);
+ if (QTypeModuleInfo<T>::IsGui)
+ return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].size : 0;
+
+ if (QTypeModuleInfo<T>::IsWidget)
+ return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].size : 0;
+
+ // This point can be reached only for known types that definition is not available, for example
+ // in bootstrap mode. We have no other choice then ignore it.
+ return 0;
{
const QVector<QCustomTypeInfo> * const ct = customTypes();
QReadLocker locker(customTypesLock());
{
const QVector<QCustomTypeInfo> * const ct = customTypes();
QReadLocker locker(customTypesLock());
- if (type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User)
+ if (Q_UNLIKELY(type < QMetaType::User || !ct || ct->count() <= type - QMetaType::User))
return 0;
return ct->at(type - QMetaType::User).size;
}
return 0;
return ct->at(type - QMetaType::User).size;
}
{
static quint32 Flags(const int type)
{
{
static quint32 Flags(const int type)
{
- return Flags::undefinedTypeFlags(type);
+ if (QTypeModuleInfo<T>::IsGui)
+ return Q_LIKELY(qMetaTypeGuiHelper) ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0;
+
+ if (QTypeModuleInfo<T>::IsWidget)
+ return Q_LIKELY(qMetaTypeWidgetsHelper) ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0;
+
+ // This point can be reached only for known types that definition is not available, for example
+ // in bootstrap mode. We have no other choice then ignore it.
+ return 0;
{}
template<typename T>
quint32 delegate(const T*) { return FlagsImpl<T>::Flags(m_type); }
{}
template<typename T>
quint32 delegate(const T*) { return FlagsImpl<T>::Flags(m_type); }
+ quint32 delegate(const void*) { return 0; }
quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return customTypeFlags(m_type); }
private:
const int m_type;
static quint32 customTypeFlags(const int type)
{
const QVector<QCustomTypeInfo> * const ct = customTypes();
quint32 delegate(const QMetaTypeSwitcher::UnknownType*) { return customTypeFlags(m_type); }
private:
const int m_type;
static quint32 customTypeFlags(const int type)
{
const QVector<QCustomTypeInfo> * const ct = customTypes();
return 0;
QReadLocker locker(customTypesLock());
return 0;
QReadLocker locker(customTypesLock());
- if (ct->count() <= type - QMetaType::User)
+ if (Q_UNLIKELY(ct->count() <= type - QMetaType::User))
return 0;
return ct->at(type - QMetaType::User).flags;
}
return 0;
return ct->at(type - QMetaType::User).flags;
}
- static quint32 undefinedTypeFlags(const int type);
-
-quint32 Flags::undefinedTypeFlags(const int type)
-{
- if (type >= QMetaType::FirstGuiType && type <= QMetaType::LastGuiType)
- return qMetaTypeGuiHelper ? qMetaTypeGuiHelper[type - QMetaType::FirstGuiType].flags : 0;
- else if (type >= QMetaType::FirstWidgetsType && type <= QMetaType::LastWidgetsType)
- return qMetaTypeWidgetsHelper ? qMetaTypeWidgetsHelper[type - QMetaType::FirstWidgetsType].flags : 0;
- return customTypeFlags(type);
-}
-
quint32 flags; // same as QMetaType::TypeFlags
};
quint32 flags; // same as QMetaType::TypeFlags
};
+template<>
+struct QMetaTypeInterface::Impl<void> {
+ static void *creator(const void *) { return 0; }
+ static void deleter(void *) {}
+#ifndef QT_NO_DATASTREAM
+ static void saver(QDataStream &, const void *) {}
+ static void loader(QDataStream &, void *) {}
+#endif // QT_NO_DATASTREAM
+ static void destructor(void *){}
+ static void *constructor(void *, const void *) { return 0; }
+};
+
#ifndef QT_NO_DATASTREAM
# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
#ifndef QT_NO_DATASTREAM
# define QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*saveOp*/(reinterpret_cast<QMetaType::SaveOperator>(QMetaTypeInterface::Impl<Type>::saver)), \
QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
/*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
QT_METATYPE_INTERFACE_INIT_DATASTREAM_IMPL(Type) \
/*constructor*/(reinterpret_cast<QMetaType::Constructor>(QMetaTypeInterface::Impl<Type>::constructor)), \
/*destructor*/(reinterpret_cast<QMetaType::Destructor>(QMetaTypeInterface::Impl<Type>::destructor)), \
- /*size*/(sizeof(Type)), \
+ /*size*/(QTypeInfo<Type>::sizeOf), \
/*flags*/(!QTypeInfo<Type>::isStatic * QMetaType::MovableType) \
| (QTypeInfo<Type>::isComplex * QMetaType::NeedsConstruction) \
| (QTypeInfo<Type>::isComplex * QMetaType::NeedsDestruction) \
/*flags*/(!QTypeInfo<Type>::isStatic * QMetaType::MovableType) \
| (QTypeInfo<Type>::isComplex * QMetaType::NeedsConstruction) \
| (QTypeInfo<Type>::isComplex * QMetaType::NeedsDestruction) \