diff options
Diffstat (limited to 'src/corelib/kernel/qmetatype.h')
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index e3ef1474da..1e944660c6 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -18,6 +18,7 @@ #include <QtCore/qobjectdefs.h> #endif #include <QtCore/qscopeguard.h> +#include <QtCore/qttypetraits.h> #include <array> #include <new> @@ -518,20 +519,20 @@ public: template<typename T> constexpr static QMetaType fromType(); static QMetaType fromName(QByteArrayView name); - - friend bool operator==(QMetaType a, QMetaType b) +private: + friend bool comparesEqual(const QMetaType &lhs, + const QMetaType &rhs) noexcept { - if (a.d_ptr == b.d_ptr) + if (lhs.d_ptr == rhs.d_ptr) return true; - if (!a.d_ptr || !b.d_ptr) + if (!lhs.d_ptr || !rhs.d_ptr) return false; // one type is undefined, the other is defined // avoid id call if we already have the id - const int aId = a.id(); - const int bId = b.id(); + const int aId = lhs.id(); + const int bId = rhs.id(); return aId == bId; } - friend bool operator!=(QMetaType a, QMetaType b) { return !(a == b); } - + Q_DECLARE_EQUALITY_COMPARABLE(QMetaType) #ifndef QT_NO_DEBUG_STREAM private: friend Q_CORE_EXPORT QDebug operator<<(QDebug d, QMetaType m); @@ -1750,11 +1751,19 @@ QT_FOR_EACH_STATIC_TYPE(Q_DECLARE_BUILTIN_METATYPE) QT_BEGIN_NAMESPACE +namespace QtPrivate { +// out-of-line helpers to reduce template code bloat ("SCARY") and improve compile times: +Q_CORE_EXPORT bool hasRegisteredConverterFunctionToPairVariantInterface(QMetaType m); +Q_CORE_EXPORT bool hasRegisteredConverterFunctionToIterableMetaSequence(QMetaType m); +Q_CORE_EXPORT bool hasRegisteredMutableViewFunctionToIterableMetaSequence(QMetaType m); +Q_CORE_EXPORT bool hasRegisteredConverterFunctionToIterableMetaAssociation(QMetaType m); +Q_CORE_EXPORT bool hasRegisteredMutableViewFunctionToIterableMetaAssociation(QMetaType m); +} + template <typename T> inline bool QtPrivate::IsMetaTypePair<T, true>::registerConverter() { - const QMetaType to = QMetaType::fromType<QtMetaTypePrivate::QPairVariantInterfaceImpl>(); - if (!QMetaType::hasRegisteredConverterFunction(QMetaType::fromType<T>(), to)) { + if (!QtPrivate::hasRegisteredConverterFunctionToPairVariantInterface(QMetaType::fromType<T>())) { QtMetaTypePrivate::QPairVariantInterfaceConvertFunctor<T> o; return QMetaType::registerConverter<T, QtMetaTypePrivate::QPairVariantInterfaceImpl>(o); } @@ -1786,8 +1795,7 @@ struct SequentialValueTypeIsMetaType<T, true> { static bool registerConverter() { - const QMetaType to = QMetaType::fromType<QIterable<QMetaSequence>>(); - if (!QMetaType::hasRegisteredConverterFunction(QMetaType::fromType<T>(), to)) { + if (!QtPrivate::hasRegisteredConverterFunctionToIterableMetaSequence(QMetaType::fromType<T>())) { QSequentialIterableConvertFunctor<T> o; return QMetaType::registerConverter<T, QIterable<QMetaSequence>>(o); } @@ -1796,8 +1804,7 @@ struct SequentialValueTypeIsMetaType<T, true> static bool registerMutableView() { - const QMetaType to = QMetaType::fromType<QIterable<QMetaSequence>>(); - if (!QMetaType::hasRegisteredMutableViewFunction(QMetaType::fromType<T>(), to)) { + if (!QtPrivate::hasRegisteredMutableViewFunctionToIterableMetaSequence(QMetaType::fromType<T>())) { QSequentialIterableMutableViewFunctor<T> o; return QMetaType::registerMutableView<T, QIterable<QMetaSequence>>(o); } @@ -1830,8 +1837,7 @@ struct AssociativeKeyTypeIsMetaType<T, true> : AssociativeMappedTypeIsMetaType<T { static bool registerConverter() { - const QMetaType to = QMetaType::fromType<QIterable<QMetaAssociation>>(); - if (!QMetaType::hasRegisteredConverterFunction(QMetaType::fromType<T>(), to)) { + if (!QtPrivate::hasRegisteredConverterFunctionToIterableMetaAssociation(QMetaType::fromType<T>())) { QAssociativeIterableConvertFunctor<T> o; return QMetaType::registerConverter<T, QIterable<QMetaAssociation>>(o); } @@ -1840,8 +1846,7 @@ struct AssociativeKeyTypeIsMetaType<T, true> : AssociativeMappedTypeIsMetaType<T static bool registerMutableView() { - const QMetaType to = QMetaType::fromType<QIterable<QMetaAssociation>>(); - if (!QMetaType::hasRegisteredMutableViewFunction(QMetaType::fromType<T>(), to)) { + if (!QtPrivate::hasRegisteredMutableViewFunctionToIterableMetaAssociation(QMetaType::fromType<T>())) { QAssociativeIterableMutableViewFunctor<T> o; return QMetaType::registerMutableView<T, QIterable<QMetaAssociation>>(o); } |