summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-02-05 15:53:39 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-03-12 17:23:11 -0800
commit45fd36f1480a6229879a4e59236ffa1d1d22dfbf (patch)
treee62c063267fe8237b37337e9c9fe435c44568c52
parentfff9f5047af79e7a8bd7345d9f22126d626e35a7 (diff)
qHash: make hashing of QLatin1StringView be the same as QString
Everywhere, except for ARM. Change-Id: I50e2158aeade4256ad1dfffd17b11ca2d57ad1fb Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/tools/qhash.cpp11
-rw-r--r--src/corelib/tools/qhashfunctions.h6
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp2
3 files changed, 8 insertions, 11 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 87ccc46d71..af393b9235 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -1140,21 +1140,12 @@ size_t qHash(QLatin1StringView key, size_t seed) noexcept
// the seed is always 0 in bootstrapped mode (no seed generation code),
// so help the compiler do dead code elimination
seed = 0;
- constexpr bool Qt6DeterministicHash = true;
-#else
- constexpr bool Qt6DeterministicHash = QT_VERSION_MAJOR == 6;
#endif
auto data = reinterpret_cast<const uchar *>(key.data());
size_t size = key.size();
- if (seed == 0 && Qt6DeterministicHash) {
- // fall back to what we used to use prior to Qt 6.8
- return qHashBits(data, size, seed);
- }
-
- // mix in the length as a secondary seed. For seed == 0, seed2 must be
- // size, to match what we used to do prior to Qt 6.2.
+ // Mix in the length as a secondary seed.
// Multiplied by 2 to match the byte size of the equiavlent UTF-16 string.
size_t seed2 = size * 2;
if (seed)
diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h
index 9056d24102..90a269deaa 100644
--- a/src/corelib/tools/qhashfunctions.h
+++ b/src/corelib/tools/qhashfunctions.h
@@ -58,6 +58,12 @@ template <> struct QHashHeterogeneousSearch<QString, QStringView> : std::true_ty
template <> struct QHashHeterogeneousSearch<QStringView, QString> : std::true_type {};
template <> struct QHashHeterogeneousSearch<QByteArray, QByteArrayView> : std::true_type {};
template <> struct QHashHeterogeneousSearch<QByteArrayView, QByteArray> : std::true_type {};
+#ifndef Q_PROCESSOR_ARM
+template <> struct QHashHeterogeneousSearch<QString, QLatin1StringView> : std::true_type {};
+template <> struct QHashHeterogeneousSearch<QStringView, QLatin1StringView> : std::true_type {};
+template <> struct QHashHeterogeneousSearch<QLatin1StringView, QString> : std::true_type {};
+template <> struct QHashHeterogeneousSearch<QLatin1StringView, QStringView> : std::true_type {};
+#endif
namespace QHashPrivate {
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index 06f18dfe9c..00ee5763ed 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -324,7 +324,7 @@ void tst_QHashFunctions::stringConsistency()
QCOMPARE(qHash(sv, seed), qHash(value, seed));
QCOMPARE(qHash(u8bav, seed), qHash(u8ba, seed));
- if (seed || QT_VERSION_MAJOR > 6) {
+ if (seed == 0 || QHashHeterogeneousSearch<QString, QLatin1StringView>::value) {
QByteArray l1ba = value.toLatin1();
QLatin1StringView l1sv(l1ba.data(), l1ba.size());
#ifdef Q_PROCESSOR_ARM