qtbase: use qHashMulti & qHashRange instead of QHashCombine

If we have no specific need for the private QHashCombine class, use the
front-end functions. For headers, we do have a need: we prefer
QHashCombine because it compiles faster.

Change-Id: I73578ea802d3b905a53bfffd504c20af0ca96cf8
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Thiago Macieira 2025-03-18 08:55:40 -07:00
parent 4647940e88
commit b10c7b1680
6 changed files with 7 additions and 20 deletions

View File

@ -428,11 +428,8 @@ bool comparesEqual(const QUrlQuery &lhs, const QUrlQuery &rhs)
size_t qHash(const QUrlQuery &key, size_t seed) noexcept size_t qHash(const QUrlQuery &key, size_t seed) noexcept
{ {
if (const QUrlQueryPrivate *d = key.d) { if (const QUrlQueryPrivate *d = key.d) {
QtPrivate::QHashCombine hash;
// keep in sync with operator==: // keep in sync with operator==:
seed = hash(seed, d->valueDelimiter); return qHashMulti(seed, d->valueDelimiter, d->pairDelimiter, d->itemList);
seed = hash(seed, d->pairDelimiter);
seed = hash(seed, d->itemList);
} }
return seed; return seed;
} }

View File

@ -1813,10 +1813,7 @@ struct RowOrColumnDefinition {
}; };
size_t qHash(const RowOrColumnDefinition &key, size_t seed = 0) noexcept size_t qHash(const RowOrColumnDefinition &key, size_t seed = 0) noexcept
{ {
QtPrivate::QHashCombine hash; return qHashMulti(seed, key.parent, key.rowOrColumn);
seed = hash(seed, key.parent);
seed = hash(seed, key.rowOrColumn);
return seed;
} }
QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(RowOrColumnDefinition) QT_SPECIALIZE_STD_HASH_TO_CALL_QHASH_BY_CREF(RowOrColumnDefinition)

View File

@ -3192,12 +3192,8 @@ size_t qHash(const QCborValue &value, size_t seed)
return qHash(value.toArray(), seed); return qHash(value.toArray(), seed);
case QCborValue::Map: case QCborValue::Map:
return qHash(value.toMap(), seed); return qHash(value.toMap(), seed);
case QCborValue::Tag: { case QCborValue::Tag:
QtPrivate::QHashCombine hash; return qHashMulti(seed, value.tag(), value.taggedValue());
seed = hash(seed, value.tag());
seed = hash(seed, value.taggedValue());
return seed;
}
case QCborValue::SimpleType: case QCborValue::SimpleType:
break; break;
case QCborValue::False: case QCborValue::False:

View File

@ -576,10 +576,7 @@ QDebug operator<<(QDebug debug, const QVersionNumber &version)
*/ */
size_t qHash(const QVersionNumber &key, size_t seed) size_t qHash(const QVersionNumber &key, size_t seed)
{ {
QtPrivate::QHashCombine hash; return qHashRange(key.begin(), key.end(), seed);
for (int i = 0; i < key.segmentCount(); ++i)
seed = hash(seed, key.segmentAt(i));
return seed;
} }
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -23,7 +23,7 @@ public:
// random values // random values
static constexpr quint64 ZeroSeed = 0; static constexpr quint64 ZeroSeed = 0;
static constexpr quint64 RandomSeed32 = 1045982819; static constexpr quint64 RandomSeed32 = 1045982819;
static constexpr quint64 RandomSeed64 = QtPrivate::QHashCombine{}(RandomSeed32, RandomSeed32); static constexpr quint64 RandomSeed64 = qHashMulti(0, RandomSeed32, RandomSeed32);
size_t seed; size_t seed;
template <typename T1, typename T2> void stdPair_template(const T1 &t1, const T2 &t2); template <typename T1, typename T2> void stdPair_template(const T1 &t1, const T2 &t2);

View File

@ -12,7 +12,7 @@
#include <QTest> #include <QTest>
static constexpr quint64 RandomSeed32 = 1045982819; static constexpr quint64 RandomSeed32 = 1045982819;
static constexpr quint64 RandomSeed64 = QtPrivate::QHashCombine{}(RandomSeed32, RandomSeed32); static constexpr quint64 RandomSeed64 = qHashMulti(0, RandomSeed32, RandomSeed32);
class tst_QHash : public QObject class tst_QHash : public QObject
{ {