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.8 6.5 Change-Id: Ibf67350f571889fd21e0acc82639c053c0d606b6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit bb846a22c37dcb085829676d8feb7c203d21c886) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
dd1349240f
commit
d027d6d9da
@ -998,10 +998,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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user