mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 09:36:08 +00:00
AK: Inline the bucket index calculation
The result of the modulo is only used in the array index, so why make the code more complex by calculating it in two different places?
This commit is contained in:
parent
8fb7739cfb
commit
509eb10df4
Notes:
sideshowbarker
2024-07-18 20:54:22 +09:00
Author: https://github.com/thislooksfun
Commit: 509eb10df4
Pull-request: https://github.com/SerenityOS/serenity/pull/6070
1 changed files with 3 additions and 6 deletions
|
@ -308,9 +308,9 @@ private:
|
||||||
{
|
{
|
||||||
if (is_empty())
|
if (is_empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
size_t bucket_index = hash % m_capacity;
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto& bucket = m_buckets[bucket_index];
|
auto& bucket = m_buckets[hash % m_capacity];
|
||||||
|
|
||||||
if (usable_bucket_for_writing && !*usable_bucket_for_writing && !bucket.used) {
|
if (usable_bucket_for_writing && !*usable_bucket_for_writing && !bucket.used) {
|
||||||
*usable_bucket_for_writing = &bucket;
|
*usable_bucket_for_writing = &bucket;
|
||||||
|
@ -323,7 +323,6 @@ private:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
hash = double_hash(hash);
|
hash = double_hash(hash);
|
||||||
bucket_index = hash % m_capacity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,14 +347,12 @@ private:
|
||||||
else if (usable_bucket_for_writing)
|
else if (usable_bucket_for_writing)
|
||||||
return *usable_bucket_for_writing;
|
return *usable_bucket_for_writing;
|
||||||
|
|
||||||
size_t bucket_index = hash % m_capacity;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto& bucket = m_buckets[bucket_index];
|
auto& bucket = m_buckets[hash % m_capacity];
|
||||||
if (!bucket.used)
|
if (!bucket.used)
|
||||||
return bucket;
|
return bucket;
|
||||||
hash = double_hash(hash);
|
hash = double_hash(hash);
|
||||||
bucket_index = hash % m_capacity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue