From 45fd36f1480a6229879a4e59236ffa1d1d22dfbf Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 5 Feb 2024 15:53:39 -0800 Subject: [PATCH] qHash: make hashing of QLatin1StringView be the same as QString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Everywhere, except for ARM. Change-Id: I50e2158aeade4256ad1dfffd17b11ca2d57ad1fb Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qhash.cpp | 11 +---------- src/corelib/tools/qhashfunctions.h | 6 ++++++ .../tools/qhashfunctions/tst_qhashfunctions.cpp | 2 +- 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(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 : std::true_ty template <> struct QHashHeterogeneousSearch : std::true_type {}; template <> struct QHashHeterogeneousSearch : std::true_type {}; template <> struct QHashHeterogeneousSearch : std::true_type {}; +#ifndef Q_PROCESSOR_ARM +template <> struct QHashHeterogeneousSearch : std::true_type {}; +template <> struct QHashHeterogeneousSearch : std::true_type {}; +template <> struct QHashHeterogeneousSearch : std::true_type {}; +template <> struct QHashHeterogeneousSearch : 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::value) { QByteArray l1ba = value.toLatin1(); QLatin1StringView l1sv(l1ba.data(), l1ba.size()); #ifdef Q_PROCESSOR_ARM