diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-03-30 14:01:02 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-03-30 13:27:51 +0000 |
commit | cb2246ad15241016063689de1600519202b87a93 (patch) | |
tree | 47f638eaf13a6acbf9f15269ac5a7e240b427910 /src/corelib/tools/qhash.cpp | |
parent | 58f9629a486ae757342bc7a85ad46f08c7d1dbbc (diff) |
Allow to chain qt_hash() calls
There are some callers of qt_hash that first build a string just to hash it.
By allowing to pass an initial value for 'h', we can chain qt_hash() calls
to avoid having to allocate memory just to hash a two-part string.
Change-Id: Ifaca82d47b2fb8c707912342c3ddd84f91e70267
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qhash.cpp')
-rw-r--r-- | src/corelib/tools/qhash.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index f83643e90a..662c304a2e 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -412,27 +412,25 @@ void qSetGlobalQHashSeed(int newSeed) results. The qt_hash functions must *never* change their results. + + This function can hash discontiguous memory by invoking it on each chunk, + passing the previous's result in the next call's \a chained argument. */ -static uint qt_hash(const QChar *p, size_t n) Q_DECL_NOTHROW +uint qt_hash(QStringView key, uint chained) Q_DECL_NOTHROW { - uint h = 0; + auto n = key.size(); + auto p = key.utf16(); + + uint h = chained; while (n--) { - h = (h << 4) + (*p++).unicode(); + h = (h << 4) + *p++; h ^= (h & 0xf0000000) >> 23; h &= 0x0fffffff; } return h; } -/*! - \internal -*/ -uint qt_hash(QStringView key) Q_DECL_NOTHROW -{ - return qt_hash(key.data(), key.size()); -} - /* The prime_deltas array contains the difference between a power of two and the next prime number: |