From a450a7c6e1e3cf4b72d4a301be5239f888ab7d84 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 18 Mar 2023 14:09:35 +0800 Subject: [PATCH] Delegate string hashing to standard library Since standard library could have platform dependent specialized hashing functions. Also the main idea is to let `qHash` handle whatever integer type `std::hash` returns and mix it with `seed` accordingly. PR #18715. --- src/base/bittorrent/sessionimpl.cpp | 2 +- src/base/digest32.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 3118b2760..0112577a2 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -125,7 +125,7 @@ namespace std { uint qHash(const std::string &key, uint seed = 0) { - return qHash(QByteArray::fromRawData(key.data(), static_cast(key.length())), seed); + return ::qHash(std::hash {}(key), seed); } } diff --git a/src/base/digest32.h b/src/base/digest32.h index ffbee3043..c4e8f26c5 100644 --- a/src/base/digest32.h +++ b/src/base/digest32.h @@ -167,6 +167,6 @@ std::size_t qHash(const Digest32 &key, const std::size_t seed = 0) template uint qHash(const Digest32 &key, const uint seed = 0) { - return static_cast((std::hash::UnderlyingType> {})(key)) ^ seed; + return ::qHash(std::hash::UnderlyingType> {}(key), seed); } #endif