diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 6c198c43655..524cdff7efe 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -559,7 +559,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]; @@ -567,7 +571,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); @@ -579,14 +583,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)