From ac2b0b958e97c41b38c42c0789d91de724d567ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Thu, 5 Dec 2024 16:04:37 +0100 Subject: [PATCH] QHash: call the different detached() overloads depending on resize Instead of using just the detached() overload taking a new size, call the two un-sized one when not resizing. The unsized overload is faster because it is inlining the reallocationHelper() function and expanding a branch by way of a constant. And drop the call to rehash in the !isDetached case, if we enter this branch we willfully 'attach' the detach guard to keep the key and values alive. Follow-up change will fix the sized detach() to use a constant again. Amends d9ad2251d9fff85a18ce5afc62bcb1230cd2820d Pick-to: 6.9 Change-Id: Ia1640766b898610d12b5df20d83cefe5ca2d4c36 Reviewed-by: Thiago Macieira --- src/corelib/tools/qhash.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index c77d2d76589..6c198c43655 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1440,11 +1440,9 @@ private: detachGuard = *this; const bool resized = shouldInsert && d->shouldGrow(); const size_t bucketIndex = bucket.toBucketIndex(d); - // Like reserve(), but unconditionally detaching if no need to grow: - if (isDetached()) - d->rehash(d->size + 1); - else - d = Data::detached(d, d->size + (shouldInsert ? 1 : 0)); + + // Must detach from detachGuard + d = resized ? Data::detached(d, d->size + 1) : Data::detached(d); bucket = resized ? d->findBucket(key) : typename Data::Bucket(d, bucketIndex); } if (shouldInsert) {