replace QVariant::cmp() method with its body

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-06-07 03:58:34 +03:00
parent 61d9154c1a
commit c0fa093f41
2 changed files with 32 additions and 55 deletions

View file

@ -49,6 +49,17 @@ QT_BEGIN_NAMESPACE
static const QLatin1String qStringListDelim = QLatin1String(",");
static inline bool qIsNumericType(int tp)
{
return (tp >= QVariant::Bool && tp <= QVariant::Float)
|| (tp >= QMetaType::Long && tp <= QMetaType::UChar);
}
static inline bool qIsFloatingPoint(int tp)
{
return tp == QVariant::Double || tp == QVariant::Float;
}
static bool isNull(const QVariant::Private *d)
{
switch(d->type) {
@ -2690,59 +2701,13 @@ bool QVariant::convert(Type t)
}
/*!
\fn bool operator==(const QVariant &v1, const QVariant &v2)
\relates QVariant
Returns true if \a v1 and \a v2 are equal; otherwise returns false.
\warning This function doesn't support custom types registered
with qRegisterMetaType().
*/
/*!
\fn bool operator!=(const QVariant &v1, const QVariant &v2)
\relates QVariant
Returns false if \a v1 and \a v2 are equal; otherwise returns true.
\warning This function doesn't support custom types registered
with qRegisterMetaType().
*/
/*! \fn bool QVariant::operator==(const QVariant &v) const
Compares this QVariant with \a v and returns true if they are
equal; otherwise returns false.
In the case of custom types, their equalness operators are not called.
Instead the values' addresses are compared.
*/
/*!
\fn bool QVariant::operator!=(const QVariant &v) const
Compares this QVariant with \a v and returns true if they are not
equal; otherwise returns false.
\warning This function doesn't support custom types registered
with qRegisterMetaType().
*/
static inline bool qIsNumericType(int tp)
{
return (tp >= QVariant::Bool && tp <= QVariant::Float)
|| (tp >= QMetaType::Long && tp <= QMetaType::UChar);
}
static inline bool qIsFloatingPoint(int tp)
{
return tp == QVariant::Double || tp == QVariant::Float;
}
/*! \internal
*/
bool QVariant::cmp(const QVariant &v) const
bool QVariant::operator==(const QVariant &v) const
{
if (d.type != v.d.type) {
if (qIsNumericType(d.type) && qIsNumericType(v.d.type)) {
@ -2758,9 +2723,19 @@ bool QVariant::cmp(const QVariant &v) const
return handler->compare(&d, &v.d);
}
/*! \internal
*/
/*!
\fn bool QVariant::operator!=(const QVariant &v) const
Compares this QVariant with \a v and returns true if they are not
equal; otherwise returns false.
\warning This function doesn't support custom types registered
with qRegisterMetaType().
*/
/*!
\internal
*/
const void *QVariant::constData() const
{
return d.ptr;
@ -2772,7 +2747,9 @@ const void *QVariant::constData() const
\internal
*/
/*! \internal */
/*!
\internal
*/
void* QVariant::data()
{
return d.ptr;

View file

@ -303,10 +303,9 @@ class Q_CORE_EXPORT QVariant
f_debugStream debugStream;
};
inline bool operator==(const QVariant &v) const
{ return cmp(v); }
bool operator==(const QVariant &v) const;
inline bool operator!=(const QVariant &v) const
{ return !cmp(v); }
{ return !operator==(v); }
protected:
friend inline bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *);
@ -320,7 +319,6 @@ protected:
static const Handler *handler;
void create(int type, const void *copy);
bool cmp(const QVariant &other) const;
private:
// force compile error, prevent QVariant(bool) to be called
@ -338,7 +336,9 @@ typedef QMap<QString, QVariant> QVariantMap;
typedef QHash<QString, QVariant> QVariantHash;
inline bool qvariant_cast_helper(const QVariant &v, QVariant::Type tp, void *ptr)
{ return QVariant::handler->convert(&v.d, tp, ptr, nullptr); }
{
return QVariant::handler->convert(&v.d, tp, ptr, nullptr);
}
template <typename T>
inline QVariant qVariantFromValue(const T &t)