diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-04 15:13:52 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-09 04:05:50 -0700 |
commit | 9ad44f28c13fa2a3129571c2283a6a72b3f86d2a (patch) | |
tree | b2ffc866c099fce13b568a1a914deac102f14f32 /src/corelib/kernel | |
parent | 393d5efda30aac8f20c35dc22b7d22c350f6f096 (diff) |
QVariant: merge the equality and ordering compare functions
As we're not doing any deep analysis, the code is almost exactly the
same anyway. It is possible to simplify further by avoiding the
signed/unsigned conversion rules, but it's not worth the
effort. Instead, we can share code.
Change-Id: I3d74c753055744deb8acfffd17248a5c51cbbfcb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 38 |
1 files changed, 2 insertions, 36 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index a8c5d756c7..b0cdf561e5 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -2226,22 +2226,6 @@ static int numericTypePromotion(const QtPrivate::QMetaTypeInterface *iface1, return QMetaType::Int; } -static bool integralEquals(uint promotedType, const QVariant::Private *d1, const QVariant::Private *d2) -{ - // use toLongLong to retrieve the data, it gets us all the bits - std::optional<qlonglong> l1 = qConvertToNumber(d1, promotedType == QMetaType::Bool); - std::optional<qlonglong> l2 = qConvertToNumber(d2, promotedType == QMetaType::Bool); - if (promotedType == QMetaType::Bool) - return bool(*l1) == bool(*l2); - if (promotedType == QMetaType::Int) - return int(*l1) == int(*l2); - if (promotedType == QMetaType::UInt) - return uint(*l1) == uint(*l2); - if (promotedType == QMetaType::ULongLong) - return qulonglong(*l1) == qulonglong(*l2); - return l1 == l2; -} - namespace { template<typename Numeric> int spaceShip(Numeric lhs, Numeric rhs) @@ -2296,18 +2280,6 @@ static std::optional<int> numericCompare(const QVariant::Private *d1, const QVar return spaceShip<qreal>(*r1, *r2); } -static bool numericEquals(const QVariant::Private *d1, const QVariant::Private *d2) -{ - uint promotedType = numericTypePromotion(d1->typeInterface(), d2->typeInterface()); - if (promotedType != QMetaType::QReal) - return integralEquals(promotedType, d1, d2); - - // qreal comparisons - std::optional<qreal> r1 = qConvertToRealNumber(d1); - std::optional<qreal> r2 = qConvertToRealNumber(d2); - return r1 == r2; -} - #ifndef QT_BOOTSTRAPPED static bool canConvertMetaObject(QMetaType fromType, QMetaType toType) { @@ -2320,12 +2292,6 @@ static bool canConvertMetaObject(QMetaType fromType, QMetaType toType) return false; } -static bool pointerEquals(const QVariant::Private *d1, const QVariant::Private *d2) -{ - // simply check whether both types point to the same data - return d1->get<QObject *>() == d2->get<QObject *>(); -} - static int pointerCompare(const QVariant::Private *d1, const QVariant::Private *d2) { return spaceShip<QObject *>(d1->get<QObject *>(), d2->get<QObject *>()); @@ -2342,11 +2308,11 @@ bool QVariant::equals(const QVariant &v) const if (metatype != v.metaType()) { // try numeric comparisons, with C++ type promotion rules (no conversion) if (qIsNumericType(metatype.id()) && qIsNumericType(v.d.type().id())) - return numericEquals(&d, &v.d); + return numericCompare(&d, &v.d) == 0; #ifndef QT_BOOTSTRAPPED // if both types are related pointers to QObjects, check if they point to the same object if (canConvertMetaObject(metatype, v.metaType())) - return pointerEquals(&d, &v.d); + return pointerCompare(&d, &v.d) == 0; #endif return false; } |