diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbitarray.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qhash.cpp | 84 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qhashfunctions.h | 79 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qset.qdoc | 2 | ||||
-rw-r--r-- | src/corelib/tools/qshareddata.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.qdoc | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvector.qdoc | 2 | ||||
-rw-r--r-- | src/corelib/tools/qversionnumber.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qversionnumber.h | 4 |
14 files changed, 98 insertions, 97 deletions
diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index ac3a8771d9..e8ef032c24 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -50,7 +50,7 @@ class Q_CORE_EXPORT QBitArray { friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QBitArray &); friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QBitArray &); - friend Q_CORE_EXPORT uint qHash(const QBitArray &key, uint seed) noexcept; + friend Q_CORE_EXPORT size_t qHash(const QBitArray &key, size_t seed) noexcept; QByteArray d; public: diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index f053341afd..ab699a7f94 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -210,11 +210,6 @@ static inline uint hash(const uchar *p, size_t len, uint seed) noexcept return h; } -uint qHashBits(const void *p, size_t len, uint seed) noexcept -{ - return hash(static_cast<const uchar*>(p), int(len), seed); -} - static inline uint hash(const QChar *p, size_t len, uint seed) noexcept { uint h = seed; @@ -228,33 +223,38 @@ static inline uint hash(const QChar *p, size_t len, uint seed) noexcept return h; } -uint qHash(const QByteArray &key, uint seed) noexcept +size_t qHashBits(const void *p, size_t size, size_t seed) noexcept +{ + return hash(static_cast<const uchar*>(p), int(size), static_cast<uint>(seed)); +} + + +size_t qHash(const QByteArray &key, size_t seed) noexcept { return hash(reinterpret_cast<const uchar *>(key.constData()), size_t(key.size()), seed); } #if QT_STRINGVIEW_LEVEL < 2 -uint qHash(const QString &key, uint seed) noexcept +size_t qHash(const QString &key, size_t seed) noexcept { return hash(key.unicode(), size_t(key.size()), seed); } -uint qHash(const QStringRef &key, uint seed) noexcept +size_t qHash(const QStringRef &key, size_t seed) noexcept { return hash(key.unicode(), size_t(key.size()), seed); } #endif -uint qHash(QStringView key, uint seed) noexcept +size_t qHash(QStringView key, size_t seed) noexcept { return hash(key.data(), key.size(), seed); } -uint qHash(const QBitArray &bitArray, uint seed) noexcept +size_t qHash(const QBitArray &bitArray, size_t seed) noexcept { int m = bitArray.d.size() - 1; - uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), - size_t(qMax(0, m)), seed); + size_t result = qHashBits(reinterpret_cast<const uchar *>(bitArray.d.constData()), size_t(qMax(0, m)), seed); // deal with the last 0 to 7 bits manually, because we can't trust that // the padding is initialized to 0 in bitArray.d @@ -264,7 +264,7 @@ uint qHash(const QBitArray &bitArray, uint seed) noexcept return result; } -uint qHash(QLatin1String key, uint seed) noexcept +size_t qHash(QLatin1String key, size_t seed) noexcept { return hash(reinterpret_cast<const uchar *>(key.data()), size_t(key.size()), seed); } @@ -406,7 +406,7 @@ uint qt_hash(QStringView key, uint chained) noexcept } /*! - \fn template <typename T1, typename T2> uint qHash(const QPair<T1, T2> &key, uint seed = 0) + \fn template <typename T1, typename T2> size_t qHash(const QPair<T1, T2> &key, size_t seed = 0) \since 5.0 \relates QHash @@ -416,7 +416,7 @@ uint qt_hash(QStringView key, uint chained) noexcept */ /*! - \fn template <typename T1, typename T2> uint qHash(const std::pair<T1, T2> &key, uint seed = 0) + \fn template <typename T1, typename T2> size_t qHash(const std::pair<T1, T2> &key, size_t seed = 0) \since 5.7 \relates QHash @@ -430,7 +430,7 @@ uint qt_hash(QStringView key, uint chained) noexcept constraints, we cannot change the QPair algorithm to match the std::pair one before Qt 6. */ -/*! \fn template <typename InputIterator> uint qHashRange(InputIterator first, InputIterator last, uint seed = 0) +/*! \fn template <typename InputIterator> size_t qHashRange(InputIterator first, InputIterator last, size_t seed = 0) \relates QHash \since 5.5 @@ -465,7 +465,7 @@ uint qt_hash(QStringView key, uint chained) noexcept \sa qHashBits(), qHashRangeCommutative() */ -/*! \fn template <typename InputIterator> uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0) +/*! \fn template <typename InputIterator> size_t qHashRangeCommutative(InputIterator first, InputIterator last, size_t seed = 0) \relates QHash \since 5.5 @@ -501,7 +501,7 @@ uint qt_hash(QStringView key, uint chained) noexcept \sa qHashBits(), qHashRange() */ -/*! \fn uint qHashBits(const void *p, size_t len, uint seed = 0) +/*! \fn size_t qHashBits(const void *p, size_t len, size_t seed = 0) \relates QHash \since 5.4 @@ -526,77 +526,77 @@ uint qt_hash(QStringView key, uint chained) noexcept \sa qHashRange(), qHashRangeCommutative() */ -/*! \fn uint qHash(char key, uint seed = 0) +/*! \fn size_t qHash(char key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(uchar key, uint seed = 0) +/*! \fn size_t qHash(uchar key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(signed char key, uint seed = 0) +/*! \fn size_t qHash(signed char key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(ushort key, uint seed = 0) +/*! \fn size_t qHash(ushort key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(short key, uint seed = 0) +/*! \fn size_t qHash(short key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(uint key, uint seed = 0) +/*! \fn size_t qHash(uint key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(int key, uint seed = 0) +/*! \fn size_t qHash(int key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(ulong key, uint seed = 0) +/*! \fn size_t qHash(ulong key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(long key, uint seed = 0) +/*! \fn size_t qHash(long key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(quint64 key, uint seed = 0) +/*! \fn size_t qHash(quint64 key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(qint64 key, uint seed = 0) +/*! \fn size_t qHash(qint64 key, size_t seed = 0) \relates QHash \since 5.0 @@ -608,7 +608,7 @@ uint qt_hash(QStringView key, uint chained) noexcept Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(float key, uint seed) noexcept +size_t qHash(float key, size_t seed) noexcept { return key != 0.0f ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } @@ -618,7 +618,7 @@ uint qHash(float key, uint seed) noexcept Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(double key, uint seed) noexcept +size_t qHash(double key, size_t seed) noexcept { return key != 0.0 ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } @@ -629,62 +629,62 @@ uint qHash(double key, uint seed) noexcept Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(long double key, uint seed) noexcept +size_t qHash(long double key, size_t seed) noexcept { return key != 0.0L ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ; } #endif -/*! \fn uint qHash(const QChar key, uint seed = 0) +/*! \fn size_t qHash(const QChar key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(const QByteArray &key, uint seed = 0) +/*! \fn size_t qHash(const QByteArray &key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(const QBitArray &key, uint seed = 0) +/*! \fn size_t qHash(const QBitArray &key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(const QString &key, uint seed = 0) +/*! \fn size_t qHash(const QString &key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(const QStringRef &key, uint seed = 0) +/*! \fn size_t qHash(const QStringRef &key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(QStringView key, uint seed = 0) +/*! \fn size_t qHash(QStringView key, size_t seed = 0) \relates QStringView \since 5.10 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn uint qHash(QLatin1String key, uint seed = 0) +/*! \fn size_t qHash(QLatin1String key, size_t seed = 0) \relates QHash \since 5.0 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -/*! \fn template <class T> uint qHash(const T *key, uint seed = 0) +/*! \fn template <class T> size_t qHash(const T *key, size_t seed = 0) \relates QHash \since 5.0 @@ -2855,7 +2855,7 @@ uint qHash(long double key, uint seed) noexcept */ /*! - \fn template <class Key, class T> uint qHash(const QHash<Key, T> &key, uint seed = 0) + \fn template <class Key, class T> size_t qHash(const QHash<Key, T> &key, size_t seed = 0) \since 5.8 \relates QHash @@ -2865,7 +2865,7 @@ uint qHash(long double key, uint seed) noexcept */ /*! - \fn template <class Key, class T> uint qHash(const QMultiHash<Key, T> &key, uint seed = 0) + \fn template <class Key, class T> size_t qHash(const QMultiHash<Key, T> &key, size_t seed = 0) \since 5.8 \relates QMultiHash diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index d5d13f7bf3..1d3f84d0ec 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -2011,7 +2011,7 @@ public: #endif // !QT_NO_JAVA_STYLE_ITERATORS template <class Key, class T> -uint qHash(const QHash<Key, T> &key, uint seed = 0) +size_t qHash(const QHash<Key, T> &key, size_t seed = 0) noexcept(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) { QtPrivate::QHashCombineCommutative hash; @@ -2024,7 +2024,7 @@ uint qHash(const QHash<Key, T> &key, uint seed = 0) } template <class Key, class T> -inline uint qHash(const QMultiHash<Key, T> &key, uint seed = 0) +inline size_t qHash(const QMultiHash<Key, T> &key, size_t seed = 0) noexcept(noexcept(qHash(std::declval<Key&>())) && noexcept(qHash(std::declval<T&>()))) { const QHash<Key, T> &key2 = key; diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h index 2e62e93ac4..de3a456f4b 100644 --- a/src/corelib/tools/qhashfunctions.h +++ b/src/corelib/tools/qhashfunctions.h @@ -70,7 +70,7 @@ Q_CORE_EXPORT void qSetGlobalQHashSeed(int newSeed); namespace QHashPrivate { -Q_DECL_CONST_FUNCTION constexpr uint hash(size_t key, uint seed) noexcept +Q_DECL_CONST_FUNCTION constexpr size_t hash(size_t key, size_t seed) noexcept { key ^= seed; if constexpr (sizeof(size_t) == 4) { @@ -86,74 +86,74 @@ Q_DECL_CONST_FUNCTION constexpr uint hash(size_t key, uint seed) noexcept key ^= key >> 32; key *= UINT64_C(0xd6e8feb86659fd93); key ^= key >> 32; - return uint(key); + return key; } } } -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHashBits(const void *p, size_t size, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHashBits(const void *p, size_t size, size_t seed = 0) noexcept; -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(char key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(char key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uchar key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(uchar key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(signed char key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(signed char key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ushort key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(ushort key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(short key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(short key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(uint key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(uint key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(int key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(int key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(ulong key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(ulong key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(long key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(long key, size_t seed = 0) noexcept { return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(quint64 key, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline size_t qHash(quint64 key, size_t seed = 0) noexcept { if (sizeof(quint64) > sizeof(size_t)) key ^= (key >> 32); return QHashPrivate::hash(size_t(key), seed); } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(qint64 key, uint seed = 0) noexcept { return qHash(quint64(key), seed); } -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(float key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(double key, uint seed = 0) noexcept; +Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(qint64 key, size_t seed = 0) noexcept { return qHash(quint64(key), seed); } +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(float key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(double key, size_t seed = 0) noexcept; #if !defined(Q_OS_DARWIN) || defined(Q_CLANG_QDOC) -Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_CONST_FUNCTION size_t qHash(long double key, size_t seed = 0) noexcept; #endif -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) noexcept { return qHash(key.unicode(), seed); } -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) noexcept; +Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(const QChar key, size_t seed = 0) noexcept { return qHash(key.unicode(), seed); } +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0) noexcept; #if QT_STRINGVIEW_LEVEL < 2 -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QStringRef &key, size_t seed = 0) noexcept; #endif -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QStringView key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) noexcept; -Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QBitArray &key, size_t seed = 0) noexcept; +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QLatin1String key, size_t seed = 0) noexcept; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept; -Q_DECL_CONST_FUNCTION inline uint qHash(std::nullptr_t, uint seed = 0) noexcept +Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(std::nullptr_t, size_t seed = 0) noexcept { - return qHash(reinterpret_cast<quintptr>(nullptr), seed); + return seed; } -template <class T> inline uint qHash(const T *key, uint seed = 0) noexcept +template <class T> inline size_t qHash(const T *key, size_t seed = 0) noexcept { return qHash(reinterpret_cast<quintptr>(key), seed); } -template<typename T> inline uint qHash(const T &t, uint seed) +template<typename T> inline size_t qHash(const T &t, size_t seed) noexcept(noexcept(qHash(t))) { return qHash(t) ^ seed; } namespace QtPrivate { struct QHashCombine { - typedef uint result_type; + typedef size_t result_type; template <typename T> - Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const noexcept(noexcept(qHash(t))) + constexpr result_type operator()(size_t seed, const T &t) const noexcept(noexcept(qHash(t))) // combiner taken from N3876 / boost::hash_combine { return seed ^ (qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2)) ; } }; @@ -164,37 +164,38 @@ struct QHashCombineCommutative { // usually what we want: {0,1,3} should hash differently than // {1,3,0}. Except when it isn't (e.g. for QSet and // QHash). Therefore, provide a commutative combiner, too. - typedef uint result_type; + typedef size_t result_type; template <typename T> - Q_DECL_CONSTEXPR result_type operator()(uint seed, const T &t) const noexcept(noexcept(qHash(t))) + constexpr result_type operator()(size_t seed, const T &t) const noexcept(noexcept(qHash(t))) { return seed + qHash(t); } // don't use xor! }; } // namespace QtPrivate template <typename InputIterator> -inline uint qHashRange(InputIterator first, InputIterator last, uint seed = 0) +inline size_t qHashRange(InputIterator first, InputIterator last, size_t seed = 0) noexcept(noexcept(qHash(*first))) // assume iterator operations don't throw { return std::accumulate(first, last, seed, QtPrivate::QHashCombine()); } template <typename InputIterator> -inline uint qHashRangeCommutative(InputIterator first, InputIterator last, uint seed = 0) +inline size_t qHashRangeCommutative(InputIterator first, InputIterator last, size_t seed = 0) noexcept(noexcept(qHash(*first))) // assume iterator operations don't throw { return std::accumulate(first, last, seed, QtPrivate::QHashCombineCommutative()); } -template <typename T1, typename T2> inline uint qHash(const QPair<T1, T2> &key, uint seed = 0) +template <typename T1, typename T2> inline size_t qHash(const QPair<T1, T2> &key, size_t seed = 0) noexcept(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) { - uint h1 = qHash(key.first, seed); - uint h2 = qHash(key.second, seed); - return ((h1 << 16) | (h1 >> 16)) ^ h2 ^ seed; + QtPrivate::QHashCombine hash; + seed = hash(seed, key.first); + seed = hash(seed, key.second); + return seed; } -template <typename T1, typename T2> inline uint qHash(const std::pair<T1, T2> &key, uint seed = 0) +template <typename T1, typename T2> inline size_t qHash(const std::pair<T1, T2> &key, size_t seed = 0) noexcept(noexcept(qHash(key.first, seed)) && noexcept(qHash(key.second, seed))) { QtPrivate::QHashCombine hash; diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index b631587177..f078e62999 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -230,7 +230,7 @@ QSet(InputIterator, InputIterator) -> QSet<ValueType>; #endif template <typename T> -uint qHash(const QSet<T> &key, uint seed = 0) +size_t qHash(const QSet<T> &key, size_t seed = 0) noexcept(noexcept(qHashRangeCommutative(key.begin(), key.end(), seed))) { return qHashRangeCommutative(key.begin(), key.end(), seed); diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc index 42dd1288ac..eb6b542181 100644 --- a/src/corelib/tools/qset.qdoc +++ b/src/corelib/tools/qset.qdoc @@ -1136,7 +1136,7 @@ */ /*! - \fn template <class T> uint qHash(const QSet<T> &key, uint seed = 0) + \fn template <class T> size_t qHash(const QSet<T> &key, size_t seed = 0) \relates QHash \since 5.5 diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index f123f8e7b9..ef3e689e92 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -305,12 +305,12 @@ Q_INLINE_TEMPLATE void swap(QExplicitlySharedDataPointer<T> &p1, QExplicitlyShar { p1.swap(p2); } template <class T> -Q_INLINE_TEMPLATE uint qHash(const QSharedDataPointer<T> &ptr, uint seed = 0) noexcept +Q_INLINE_TEMPLATE size_t qHash(const QSharedDataPointer<T> &ptr, size_t seed = 0) noexcept { return qHash(ptr.data(), seed); } template <class T> -Q_INLINE_TEMPLATE uint qHash(const QExplicitlySharedDataPointer<T> &ptr, uint seed = 0) noexcept +Q_INLINE_TEMPLATE size_t qHash(const QExplicitlySharedDataPointer<T> &ptr, size_t seed = 0) noexcept { return qHash(ptr.data(), seed); } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 362d57fb9a..b6aad5ff73 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -882,7 +882,7 @@ Q_INLINE_TEMPLATE bool operator<(T *ptr1, const QSharedPointer<X> &ptr2) // qHash // template <class T> -Q_INLINE_TEMPLATE uint qHash(const QSharedPointer<T> &ptr, uint seed = 0) +Q_INLINE_TEMPLATE size_t qHash(const QSharedPointer<T> &ptr, size_t seed = 0) { return QT_PREPEND_NAMESPACE(qHash)(ptr.data(), seed); } diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a0de6bf2a1..cf5e2ee8c7 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -611,7 +611,7 @@ inline bool operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengt } template <typename T, qsizetype Prealloc> -uint qHash(const QVarLengthArray<T, Prealloc> &key, uint seed = 0) +size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0) noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) { return qHashRange(key.cbegin(), key.cend(), seed); diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc index a20583c73a..e43d6f152a 100644 --- a/src/corelib/tools/qvarlengtharray.qdoc +++ b/src/corelib/tools/qvarlengtharray.qdoc @@ -903,7 +903,7 @@ */ /*! - \fn template <typename T, qsizetype Prealloc> uint qHash(const QVarLengthArray<T, Prealloc> &key, uint seed = 0) + \fn template <typename T, qsizetype Prealloc> size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0) \relates QVarLengthArray \since 5.14 diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index c4670a0817..f973907714 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -731,7 +731,7 @@ Q_DECLARE_SEQUENTIAL_ITERATOR(Vector) Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(Vector) template <typename T> -uint qHash(const QVector<T> &key, uint seed = 0) +size_t qHash(const QVector<T> &key, size_t seed = 0) noexcept(noexcept(qHashRange(key.cbegin(), key.cend(), seed))) { return qHashRange(key.cbegin(), key.cend(), seed); diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc index daa6ff95e9..cbb118ddb9 100644 --- a/src/corelib/tools/qvector.qdoc +++ b/src/corelib/tools/qvector.qdoc @@ -391,7 +391,7 @@ */ /*! - \fn template <typename T> uint qHash(const QVector<T> &key, uint seed = 0) + \fn template <typename T> size_t qHash(const QVector<T> &key, size_t seed = 0) \since 5.6 \relates QVector diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index 0883896751..267f618020 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -541,14 +541,14 @@ QDebug operator<<(QDebug debug, const QVersionNumber &version) #endif /*! - \fn uint qHash(const QVersionNumber &key, uint seed) + \fn size_t qHash(const QVersionNumber &key, size_t seed) \relates QHash \since 5.6 Returns the hash value for the \a key, using \a seed to seed the calculation. */ -uint qHash(const QVersionNumber &key, uint seed) +size_t qHash(const QVersionNumber &key, size_t seed) { QtPrivate::QHashCombine hash; for (int i = 0; i < key.segmentCount(); ++i) diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index f31cdc92a6..c5756bdfb0 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE class QVersionNumber; -Q_CORE_EXPORT uint qHash(const QVersionNumber &key, uint seed = 0); +Q_CORE_EXPORT size_t qHash(const QVersionNumber &key, size_t seed = 0); #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream& operator<<(QDataStream &out, const QVersionNumber &version); @@ -283,7 +283,7 @@ private: #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version); #endif - friend Q_CORE_EXPORT uint qHash(const QVersionNumber &key, uint seed); + friend Q_CORE_EXPORT size_t qHash(const QVersionNumber &key, size_t seed); }; Q_DECLARE_TYPEINFO(QVersionNumber, Q_MOVABLE_TYPE); |