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

Unified Diff: src/base/hashmap.h

Issue 2336553002: [interpreter] Use hashmap for ConstantArrayBuilder's constant map (Closed)
Patch Set: Rebase Created 4 years, 3 months 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 | src/interpreter/constant-array-builder.h » ('j') | 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 7ecd68b592bfe50f6663941841bd74f707a7b473..ce72f84d2ad05a3f1b4e5d03fa80b9e208f7e774 100644
--- a/src/base/hashmap.h
+++ b/src/base/hashmap.h
@@ -52,6 +52,13 @@ class TemplateHashMapImpl {
Entry* LookupOrInsert(const Key& key, uint32_t hash,
AllocationPolicy allocator = AllocationPolicy());
+ // If an entry with matching key is found, returns that entry.
+ // If no matching entry is found, a new entry is inserted with
+ // corresponding key, key hash, and value created by func.
+ template <typename Func>
+ Entry* LookupOrInsert(const Key& key, uint32_t hash, const Func& value_func,
+ AllocationPolicy allocator = AllocationPolicy());
+
Entry* InsertNew(const Key& key, uint32_t hash,
AllocationPolicy allocator = AllocationPolicy());
@@ -126,13 +133,23 @@ template <typename Key, typename Value, typename MatchFun,
typename TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Entry*
TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::LookupOrInsert(
const Key& key, uint32_t hash, AllocationPolicy allocator) {
+ return LookupOrInsert(key, hash, []() { return Value(); }, allocator);
+}
+
+template <typename Key, typename Value, typename MatchFun,
+ class AllocationPolicy>
+template <typename Func>
+typename TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::Entry*
+TemplateHashMapImpl<Key, Value, MatchFun, AllocationPolicy>::LookupOrInsert(
+ const Key& key, uint32_t hash, const Func& value_func,
+ AllocationPolicy allocator) {
// Find a matching entry.
Entry* entry = Probe(key, hash);
if (entry->exists()) {
return entry;
}
- return FillEmptyEntry(entry, key, Value(), hash, allocator);
+ return FillEmptyEntry(entry, key, value_func(), hash, allocator);
}
template <typename Key, typename Value, typename MatchFun,
« no previous file with comments | « no previous file | src/interpreter/constant-array-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698