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 <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2024-12-05 16:04:37 +01:00
parent 2d2ee56942
commit ac2b0b958e

View File

@ -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) {