diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 62f7e9be640..3a3e1842b99 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -558,7 +558,11 @@ struct Data seed = QHashSeed::globalSeed(); } - void reallocationHelper(const Data &other, size_t nSpans, bool resized) + // The Resized parameter is a template param to make sure the compiler will get rid of the + // branch, for performance. + template + Q_ALWAYS_INLINE + void reallocationHelper(const Data &other, size_t nSpans) { for (size_t s = 0; s < nSpans; ++s) { const Span &span = other.spans[s]; @@ -566,7 +570,7 @@ struct Data if (!span.hasNode(index)) continue; const Node &n = span.at(index); - auto it = resized ? findBucket(n.key) : Bucket { spans + s, index }; + auto it = Resized ? findBucket(n.key) : Bucket { spans + s, index }; Q_ASSERT(it.isUnused()); Node *newNode = it.insert(); new (newNode) Node(n); @@ -578,14 +582,14 @@ struct Data { auto r = allocateSpans(numBuckets); spans = r.spans; - reallocationHelper(other, r.nSpans, false); + reallocationHelper(other, r.nSpans); } Data(const Data &other, size_t reserved) : size(other.size), seed(other.seed) { numBuckets = GrowthPolicy::bucketsForCapacity(qMax(size, reserved)); spans = allocateSpans(numBuckets).spans; size_t otherNSpans = other.numBuckets >> SpanConstants::SpanShift; - reallocationHelper(other, otherNSpans, numBuckets != other.numBuckets); + reallocationHelper(other, otherNSpans); } static Data *detached(Data *d)