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>
This commit is contained in:
parent
288326eaf8
commit
9a4da4569a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user