From 0120d8ea1e49c61c2e218fe1eee952496ef3a0ee Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 27 Aug 2024 10:19:07 -0700 Subject: [PATCH] QMetaType: inline isValid() and isRegistered() isValid() is (or could be) used in a lot of places, so make it inline. One could effectively write it as: mt == QMetaType() And rely on comparesEqual() knowing that an invalid type cannot equal to a valid one. I'm inlining isRegistered() because it's a simple function. I chose to use the QT6_DECL_NEW_OVERLOAD technique instead of QT_CORE_INLINED_SINCE because the latter does not apply inlining to QtCore itself (aside from LTO). Change-Id: I0e727ab80c42d51867d0fffd2f9641bc88f926b1 Reviewed-by: Fabian Kosmale --- src/corelib/compat/removed_api.cpp | 12 ++++++++++++ src/corelib/kernel/qmetatype.cpp | 8 -------- src/corelib/kernel/qmetatype.h | 14 ++++++++++++++ src/corelib/kernel/qvariant.h | 2 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index d0adfca59ef..1e05433d926 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -1245,6 +1245,18 @@ QUuid QUuid::createUuidV5(const QUuid &ns, const QByteArray &baseData) noexcept #endif // QT_CORE_REMOVED_SINCE(6, 8) #if QT_CORE_REMOVED_SINCE(6, 9) +#include "qmetatype.h" + +bool QMetaType::isRegistered() const +{ + return isRegistered(QT6_CALL_NEW_OVERLOAD); +} + +bool QMetaType::isValid() const +{ + return isValid(QT6_CALL_NEW_OVERLOAD); +} + #include "quuid.h" diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index aaefb57e615..327c10ec3bb 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -512,10 +512,6 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte \sa isRegistered() */ -bool QMetaType::isValid() const -{ - return d_ptr; -} /*! \fn bool QMetaType::isRegistered() const @@ -527,10 +523,6 @@ bool QMetaType::isValid() const \sa qRegisterMetaType(), isValid() */ -bool QMetaType::isRegistered() const -{ - return d_ptr && d_ptr->typeId.loadRelaxed(); -} /*! \fn int QMetaType::id() const diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 531b1330d59..e5bb6966130 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -457,8 +457,12 @@ public: explicit constexpr QMetaType(const QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {} constexpr QMetaType() = default; +#if QT_CORE_REMOVED_SINCE(6, 9) bool isValid() const; bool isRegistered() const; +#endif + constexpr bool isValid(QT6_DECL_NEW_OVERLOAD) const noexcept; + inline bool isRegistered(QT6_DECL_NEW_OVERLOAD) const noexcept; void registerType() const { // "register" is a reserved keyword @@ -2640,6 +2644,16 @@ constexpr QMetaType QMetaType::fromType() return QMetaType(QtPrivate::qMetaTypeInterfaceForType()); } +constexpr bool QMetaType::isValid(QT6_IMPL_NEW_OVERLOAD) const noexcept +{ + return d_ptr; +} + +bool QMetaType::isRegistered(QT6_IMPL_NEW_OVERLOAD) const noexcept +{ + return d_ptr && d_ptr->typeId.loadRelaxed(); +} + constexpr qsizetype QMetaType::sizeOf() const { return d_ptr ? d_ptr->size : 0; diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index fd427db1b29..6181f3d97ab 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -713,7 +713,7 @@ public: inline bool QVariant::isValid() const { - return d.type().isValid(); + return d.type().isValid(QT6_CALL_NEW_OVERLOAD); } #ifndef QT_NO_DATASTREAM