diff options
author | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-04-30 15:27:02 +0200 |
---|---|---|
committer | Tatiana Borisova <tatiana.borisova@qt.io> | 2024-05-10 21:54:54 +0200 |
commit | 5a0faa9198c6ae6e21a550159c4284d1a9c5792e (patch) | |
tree | 4bb864f28f5a995b9f657898fc26ea994d5253c0 /src | |
parent | ced943e936e335a16e9b479a2010e5bbee1af4f1 (diff) |
QMetaType: use modern comparisons
Internal QPropertyBindingPrivatePtr, QArgumentType classes
also have been updated;
Replace class operators operator==(), operator!=() of
QRegularExpression to friend method comparesEqual() and
Q_DECLARE_EQUALITY_COMPARABLE macro.
Task-number: QTBUG-120304
Change-Id: I010617cbcb8bd6afb7c21ee4345398648821f72c
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmetaobject_p.h | 20 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 13 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 16 | ||||
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 34 |
4 files changed, 36 insertions, 47 deletions
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index d2c36fceb4..d5dc9a356a 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -111,22 +111,18 @@ public: const_cast<QArgumentType *>(this)->_name = QMetaType(_type).name(); return _name; } - bool operator==(const QArgumentType &other) const - { - if (_type && other._type) - return _type == other._type; - else - return name() == other.name(); - } - bool operator!=(const QArgumentType &other) const + +private: + friend bool comparesEqual(const QArgumentType &lhs, + const QArgumentType &rhs) noexcept { - if (_type && other._type) - return _type != other._type; + if (lhs._type && rhs._type) + return lhs._type == rhs._type; else - return name() != other.name(); + return lhs.name() == rhs.name(); } + Q_DECLARE_EQUALITY_COMPARABLE(QArgumentType) -private: int _type; QByteArray _name; }; diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 387c0f49ab..9a57f46cbf 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -474,6 +474,7 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte \ingroup objectmodel \threadsafe + \compares equality The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. It associates a type @@ -925,20 +926,20 @@ void QMetaType::unregisterMetaType(QMetaType type) Returns the QMetaType corresponding to the type in the template parameter. */ -/*! \fn bool QMetaType::operator==(QMetaType a, QMetaType b) +/*! \fn bool QMetaType::operator==(const QMetaType &lhs, const QMetaType &rhs) \since 5.15 \overload - Returns \c true if the QMetaType \a a represents the same type - as the QMetaType \a b, otherwise returns \c false. + Returns \c true if the QMetaType \a lhs represents the same type + as the QMetaType \a rhs, otherwise returns \c false. */ -/*! \fn bool QMetaType::operator!=(QMetaType a, QMetaType b) +/*! \fn bool QMetaType::operator!=(const QMetaType &lhs, const QMetaType &rhs) \since 5.15 \overload - Returns \c true if the QMetaType \a a represents a different type - than the QMetaType \a b, otherwise returns \c false. + Returns \c true if the QMetaType \a lhs represents a different type + than the QMetaType \a rhs, otherwise returns \c false. */ /*! \internal */ diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index e3ef1474da..80d10f5c9a 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -518,20 +518,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); diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 86dc08a6bc..a8456721d0 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -95,28 +95,20 @@ public: void swap(QPropertyBindingPrivatePtr &other) noexcept { qt_ptr_swap(d, other.d); } - friend bool operator==(const QPropertyBindingPrivatePtr &p1, const QPropertyBindingPrivatePtr &p2) noexcept - { return p1.d == p2.d; } - friend bool operator!=(const QPropertyBindingPrivatePtr &p1, const QPropertyBindingPrivatePtr &p2) noexcept - { return p1.d != p2.d; } - friend bool operator==(const QPropertyBindingPrivatePtr &p1, const T *ptr) noexcept - { return p1.d == ptr; } - friend bool operator!=(const QPropertyBindingPrivatePtr &p1, const T *ptr) noexcept - { return p1.d != ptr; } - friend bool operator==(const T *ptr, const QPropertyBindingPrivatePtr &p2) noexcept - { return ptr == p2.d; } - friend bool operator!=(const T *ptr, const QPropertyBindingPrivatePtr &p2) noexcept - { return ptr != p2.d; } - friend bool operator==(const QPropertyBindingPrivatePtr &p1, std::nullptr_t) noexcept - { return !p1; } - friend bool operator!=(const QPropertyBindingPrivatePtr &p1, std::nullptr_t) noexcept - { return p1; } - friend bool operator==(std::nullptr_t, const QPropertyBindingPrivatePtr &p2) noexcept - { return !p2; } - friend bool operator!=(std::nullptr_t, const QPropertyBindingPrivatePtr &p2) noexcept - { return p2; } - private: + friend bool comparesEqual(const QPropertyBindingPrivatePtr &lhs, + const QPropertyBindingPrivatePtr &rhs) noexcept + { return lhs.d == rhs.d; } + Q_DECLARE_EQUALITY_COMPARABLE(QPropertyBindingPrivatePtr) + friend bool comparesEqual(const QPropertyBindingPrivatePtr &lhs, + const T *rhs) noexcept + { return lhs.d == rhs; } + Q_DECLARE_EQUALITY_COMPARABLE(QPropertyBindingPrivatePtr, T*) + friend bool comparesEqual(const QPropertyBindingPrivatePtr &lhs, + std::nullptr_t) noexcept + { return !lhs; } + Q_DECLARE_EQUALITY_COMPARABLE(QPropertyBindingPrivatePtr, std::nullptr_t) + QtPrivate::RefCounted *d; }; |