From b325a93e3458aadd82fb4eeb1104c53403116165 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 26 Nov 2024 12:17:21 +0100 Subject: [PATCH] Mild optimization of qt_hash Move one AND operation out of the loop, as it is only needed in the end. Change-Id: I48adcd18c900654830a84813f26c95eee579b49d Reviewed-by: Thiago Macieira (cherry picked from commit fc947593ef78c92b67811ac14dae200b45b480ea) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qhash.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index c293cf11feb..9654a6712b0 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -1085,16 +1085,13 @@ void qSetGlobalQHashSeed(int newSeed) */ uint qt_hash(QStringView key, uint chained) noexcept { - auto n = key.size(); - auto p = key.utf16(); - uint h = chained; - while (n--) { - h = (h << 4) + *p++; + for (auto c: key) { + h = (h << 4) + c.unicode(); h ^= (h & 0xf0000000) >> 23; - h &= 0x0fffffff; } + h &= 0x0fffffff; return h; }