diff options
author | thislooksfun <tlf@thislooks.fun> | 2021-04-01 20:52:32 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-02 12:54:54 +0200 |
commit | 509eb10df481707e7291bfa144450c2142e3b46d (patch) | |
tree | 7d7f075c4a5cb10f5b1bdf4c498fd933bf5bcea3 /AK | |
parent | 8fb7739cfba6111e8d7c7ac8cf8b0a8d3c1d7b01 (diff) | |
download | serenity-509eb10df481707e7291bfa144450c2142e3b46d.zip |
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?
Diffstat (limited to 'AK')
-rw-r--r-- | AK/HashTable.h | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/AK/HashTable.h b/AK/HashTable.h index d0e5df44b3..a4db28443b 100644 --- a/AK/HashTable.h +++ b/AK/HashTable.h @@ -308,9 +308,9 @@ private: { if (is_empty()) return nullptr; - size_t bucket_index = hash % m_capacity; + 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) { *usable_bucket_for_writing = &bucket; @@ -323,7 +323,6 @@ private: return nullptr; hash = double_hash(hash); - bucket_index = hash % m_capacity; } } @@ -348,14 +347,12 @@ private: else if (usable_bucket_for_writing) return *usable_bucket_for_writing; - size_t bucket_index = hash % m_capacity; for (;;) { - auto& bucket = m_buckets[bucket_index]; + auto& bucket = m_buckets[hash % m_capacity]; if (!bucket.used) return bucket; hash = double_hash(hash); - bucket_index = hash % m_capacity; } } |