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
|
Node *findNode(const Key &key) const noexcept
|
||||||
{
|
{
|
||||||
Q_ASSERT(numBuckets > 0);
|
auto bucket = findBucket(key);
|
||||||
size_t hash = QHashPrivate::calculateHash(key, seed);
|
if (bucket.isUnused())
|
||||||
Bucket bucket(this, GrowthPolicy::bucketForHash(numBuckets, hash));
|
return nullptr;
|
||||||
// loop over the buckets until we find the entry we search for
|
return bucket.node();
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InsertionResult
|
struct InsertionResult
|
||||||
|
Loading…
x
Reference in New Issue
Block a user