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

Side by Side Diff: src/interpreter/constant-array-builder.cc

Issue 2336553002: [interpreter] Use hashmap for ConstantArrayBuilder's constant map (Closed)
Patch Set: Rebased onto master 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/interpreter/constant-array-builder.h" 5 #include "src/interpreter/constant-array-builder.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 STATIC_CONST_MEMBER_DEFINITION const size_t ConstantArrayBuilder::k8BitCapacity; 67 STATIC_CONST_MEMBER_DEFINITION const size_t ConstantArrayBuilder::k8BitCapacity;
68 STATIC_CONST_MEMBER_DEFINITION const size_t 68 STATIC_CONST_MEMBER_DEFINITION const size_t
69 ConstantArrayBuilder::k16BitCapacity; 69 ConstantArrayBuilder::k16BitCapacity;
70 STATIC_CONST_MEMBER_DEFINITION const size_t 70 STATIC_CONST_MEMBER_DEFINITION const size_t
71 ConstantArrayBuilder::k32BitCapacity; 71 ConstantArrayBuilder::k32BitCapacity;
72 72
73 ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone, 73 ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone,
74 Handle<Object> the_hole_value) 74 Handle<Object> the_hole_value)
75 : constants_map_(zone), 75 : constants_map_(zone, 16),
76 smi_map_(zone), 76 smi_map_(zone),
77 smi_pairs_(zone), 77 smi_pairs_(zone),
78 the_hole_value_(the_hole_value) { 78 the_hole_value_(the_hole_value) {
79 idx_slice_[0] = 79 idx_slice_[0] =
80 new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte); 80 new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte);
81 idx_slice_[1] = new (zone) ConstantArraySlice( 81 idx_slice_[1] = new (zone) ConstantArraySlice(
82 zone, k8BitCapacity, k16BitCapacity, OperandSize::kShort); 82 zone, k8BitCapacity, k16BitCapacity, OperandSize::kShort);
83 idx_slice_[2] = new (zone) ConstantArraySlice( 83 idx_slice_[2] = new (zone) ConstantArraySlice(
84 zone, k8BitCapacity + k16BitCapacity, k32BitCapacity, OperandSize::kQuad); 84 zone, k8BitCapacity + k16BitCapacity, k32BitCapacity, OperandSize::kQuad);
85 } 85 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 slice->capacity() - slice->size()); 146 slice->capacity() - slice->size());
147 for (size_t i = 0; i < padding; i++) { 147 for (size_t i = 0; i < padding; i++) {
148 fixed_array->set(array_index++, *the_hole_value()); 148 fixed_array->set(array_index++, *the_hole_value());
149 } 149 }
150 } 150 }
151 DCHECK_EQ(array_index, fixed_array->length()); 151 DCHECK_EQ(array_index, fixed_array->length());
152 return fixed_array; 152 return fixed_array;
153 } 153 }
154 154
155 size_t ConstantArrayBuilder::Insert(Handle<Object> object) { 155 size_t ConstantArrayBuilder::Insert(Handle<Object> object) {
156 auto entry = constants_map_.find(object.address()); 156 return constants_map_.LookupOrInsert(object.address(),
157 return (entry == constants_map_.end()) ? AllocateEntry(object) 157 [&]() { return AllocateIndex(object); });
158 : entry->second;
159 } 158 }
160 159
161 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateEntry( 160 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateEntry(
162 Handle<Object> object) { 161 Handle<Object> object) {
163 index_t index = AllocateIndex(object); 162 index_t index = AllocateIndex(object);
164 constants_map_[object.address()] = index; 163 constants_map_[object.address()] = index;
165 return index; 164 return index;
166 } 165 }
167 166
168 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateIndex( 167 ConstantArrayBuilder::index_t ConstantArrayBuilder::AllocateIndex(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 return index; 247 return index;
249 } 248 }
250 249
251 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) { 250 void ConstantArrayBuilder::DiscardReservedEntry(OperandSize operand_size) {
252 OperandSizeToSlice(operand_size)->Unreserve(); 251 OperandSizeToSlice(operand_size)->Unreserve();
253 } 252 }
254 253
255 } // namespace interpreter 254 } // namespace interpreter
256 } // namespace internal 255 } // namespace internal
257 } // namespace v8 256 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698