Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: src/base/hashmap.h

Issue 2488423003: [base] Probe hashmap using indices rather than pointers (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/hashmap.h
diff --git a/src/base/hashmap.h b/src/base/hashmap.h
index 54038c5ef350d00423b0d36607e964b96b77a9bc..d2fc1337a646e77cd833bce3c6881aeb59e25f01 100644
--- a/src/base/hashmap.h
+++ b/src/base/hashmap.h
@@ -229,9 +229,8 @@ template <typename Key, typename Value, typename MatchFun,
class AllocationPolicy>
void TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Clear() {
// Mark all entries as empty.
- const Entry* end = map_end();
- for (Entry* entry = map_; entry < end; entry++) {
- entry->clear();
+ for (size_t i = 0; i < capacity_; ++i) {
+ map_[i].clear();
}
occupancy_ = 0;
}
@@ -264,19 +263,15 @@ typename TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Entry*
TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Probe(
const Key& key, uint32_t hash) const {
DCHECK(base::bits::IsPowerOfTwo32(capacity_));
- Entry* entry = map_ + (hash & (capacity_ - 1));
- const Entry* end = map_end();
- DCHECK(map_ <= entry && entry < end);
+ size_t i = hash & (capacity_ - 1);
+ DCHECK(i < capacity_);
DCHECK(occupancy_ < capacity_); // Guarantees loop termination.
- while (entry->exists() && !match_(hash, entry->hash, key, entry->key)) {
- entry++;
- if (entry >= end) {
- entry = map_;
- }
+ while (map_[i].exists() && !match_(hash, map_[i].hash, key, map_[i].key)) {
+ i = (i + 1) & (capacity_ - 1);
}
- return entry;
+ return &map_[i];
}
template <typename Key, typename Value, typename MatchFun,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698