summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin/quuid.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2025-03-18 16:43:13 +0100
committerMarc Mutz <marc.mutz@qt.io>2025-03-19 21:30:15 +0000
commitbb846a22c37dcb085829676d8feb7c203d21c886 (patch)
tree40d7d706834e840976b15dcbc92fe67df663e266 /src/corelib/plugin/quuid.cpp
parent4a154170773199f5b3376496c7b1a1c4530744e9 (diff)
QUuid: fix qHash() on 64-bit platforms
The old implementation from Qt 5 time only affected the 32 LSB of the result. The upper bits were completely determined by the seed, and the seed alone. To see this, note that all except the seed are at most 32-bit values, and no shifting out of that range occurs, either. Fix by just using qHashBits(), making sure (with a static_assert()) that QUuid has unique object representation (= can be compared for equality using memcmp()). [ChangeLog][QtCore][QUuid] Improved the performance of the qHash() function on 64-bit platforms by populating all bits of the output (was: only lower 32 bits). Amends 55d68a16aafb93aa15bcdbd78892006777b6067a. Pick-to: 6.9 6.8 6.5 Change-Id: Ibf67350f571889fd21e0acc82639c053c0d606b6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/plugin/quuid.cpp')
-rw-r--r--src/corelib/plugin/quuid.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 77b9696eb51..e0e395ab1a0 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -994,10 +994,9 @@ QDebug operator<<(QDebug dbg, const QUuid &id)
*/
size_t qHash(const QUuid &uuid, size_t seed) noexcept
{
- return uuid.data1 ^ uuid.data2 ^ (uuid.data3 << 16)
- ^ ((uuid.data4[0] << 24) | (uuid.data4[1] << 16) | (uuid.data4[2] << 8) | uuid.data4[3])
- ^ ((uuid.data4[4] << 24) | (uuid.data4[5] << 16) | (uuid.data4[6] << 8) | uuid.data4[7])
- ^ seed;
+ static_assert(std::has_unique_object_representations_v<QUuid>,
+ "Can't use qHashBits() if the type has padding holes.");
+ return qHashBits(&uuid, sizeof(QUuid), seed);
}