summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2023-05-29 16:27:36 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2023-06-01 19:10:11 +0200
commit9a4da4569a651f519d44ddd30fc67c25f52ed51c (patch)
treec5188df1eeb4c353295797c7d1b244143c47006b /src
parent288326eaf8819f9c3bf978bd11af8ea0ce3ca4f0 (diff)
QHash: reduce duplication between two lookups
findNode and findBucket are virtually the same Change-Id: I9ba8534d66f0feaa2dea7c2b9beacf8d5faddb52 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars@knoll.priv.no> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qhash.h20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 9b29429591..a4de3e377c 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -699,22 +699,10 @@ struct Data
Node *findNode(const Key &key) const noexcept
{
- Q_ASSERT(numBuckets > 0);
- size_t hash = QHashPrivate::calculateHash(key, seed);
- Bucket bucket(this, GrowthPolicy::bucketForHash(numBuckets, hash));
- // loop over the buckets until we find the entry we search for
- // or an empty slot, in which case we know the entry doesn't exist
- while (true) {
- size_t offset = bucket.offset();
- if (offset == SpanConstants::UnusedEntry) {
- return nullptr;
- } else {
- Node &n = bucket.nodeAtOffset(offset);
- if (qHashEquals(n.key, key))
- return &n;
- }
- bucket.advanceWrapped(this);
- }
+ auto bucket = findBucket(key);
+ if (bucket.isUnused())
+ return nullptr;
+ return bucket.node();
}
struct InsertionResult