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

Unified Diff: src/interpreter/constant-array-builder.cc

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 | « src/interpreter/constant-array-builder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/constant-array-builder.cc
diff --git a/src/interpreter/constant-array-builder.cc b/src/interpreter/constant-array-builder.cc
index ff3823fde2d14ce96bbc135ac00ad11cd765c5d5..a6ffd45686022d4b99812836c53d08d1fa642f2f 100644
--- a/src/interpreter/constant-array-builder.cc
+++ b/src/interpreter/constant-array-builder.cc
@@ -4,6 +4,7 @@
#include "src/interpreter/constant-array-builder.h"
+#include <functional>
#include <set>
#include "src/isolate.h"
@@ -72,9 +73,10 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone,
Handle<Object> the_hole_value)
- : constants_map_(zone),
+ : constants_map_(std::equal_to<Address>(), 16, ZoneAllocationPolicy(zone)),
smi_map_(zone),
smi_pairs_(zone),
+ zone_(zone),
the_hole_value_(the_hole_value) {
idx_slice_[0] =
new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte);
@@ -153,16 +155,11 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
}
size_t ConstantArrayBuilder::Insert(Handle<Object> object) {
- auto entry = constants_map_.find(object.address());
- return (entry == constants_map_.end()) ? AllocateEntry(object)
- : entry->second;
-}
-
-ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateEntry(
- Handle<Object> object) {
- index_t index = AllocateIndex(object);
- constants_map_[object.address()] = index;
- return index;
+ return constants_map_
+ .LookupOrInsert(object.address(), ObjectHash(object.address()),
+ [&]() { return AllocateIndex(object); },
+ ZoneAllocationPolicy(zone_))
+ ->value;
}
ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateIndex(
« no previous file with comments | « src/interpreter/constant-array-builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698