Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index 5947643733d67e6835047cc3eb5f6a3d799a980b..7bbd6144f5612d558746e66582fe7e713b1f64ae 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -12648,6 +12648,85 @@ void HOptimizedGraphBuilder::GenerateMapGetSize(CallRuntime* call) { |
} |
+template <typename CollectionType> |
+HValue* HOptimizedGraphBuilder::BuildAllocateOrderedHashTable() { |
+ static const int kInitialCapacity = CollectionType::kMinCapacity; |
+ static const int kInitialNumBuckets = |
+ kInitialCapacity / CollectionType::kLoadFactor; |
+ static const int kInitialFixedArrayLength = |
+ CollectionType::kHashTableStartIndex + kInitialNumBuckets + |
+ (kInitialCapacity * CollectionType::kEntrySize); |
+ static const int kSizeInBytes = |
+ FixedArray::kHeaderSize + (kInitialFixedArrayLength * kPointerSize); |
+ |
+ // Allocate the table and add the proper map. |
+ HValue* table = |
+ Add<HAllocate>(Add<HConstant>(kSizeInBytes), HType::HeapObject(), |
+ NOT_TENURED, FIXED_ARRAY_TYPE); |
+ AddStoreMapConstant(table, isolate()->factory()->ordered_hash_table_map()); |
+ |
+ // Initialize the FixedArray... |
+ HValue* length = Add<HConstant>(kInitialFixedArrayLength); |
+ Add<HStoreNamedField>(table, HObjectAccess::ForFixedArrayLength(), length); |
+ |
+ // ...and the OrderedHashTable fields. |
+ Add<HStoreNamedField>( |
+ table, |
+ HObjectAccess::ForOrderedHashTableNumberOfBuckets<CollectionType>(), |
+ Add<HConstant>(kInitialNumBuckets)); |
+ Add<HStoreNamedField>( |
+ table, |
+ HObjectAccess::ForOrderedHashTableNumberOfElements<CollectionType>(), |
+ graph()->GetConstant0()); |
+ Add<HStoreNamedField>( |
+ table, HObjectAccess::ForOrderedHashTableNumberOfDeletedElements< |
+ CollectionType>(), |
+ graph()->GetConstant0()); |
+ |
+ static const int kDataTableStartIndex = |
+ CollectionType::kHashTableStartIndex + kInitialNumBuckets; |
+ |
+ // Fill the buckets with kNotFound. |
+ HValue* not_found = Add<HConstant>(CollectionType::kNotFound); |
+ for (int i = CollectionType::kHashTableStartIndex; i < kDataTableStartIndex; |
+ ++i) { |
+ Add<HStoreKeyed>(table, Add<HConstant>(i), not_found, FAST_ELEMENTS); |
Dmitry Lomov (no reviews)
2014/12/09 20:48:51
This should use HStoreNamedField.
adamk
2014/12/09 21:16:59
What do you have in mind? There's a variety of HOb
Dmitry Lomov (no reviews)
2014/12/09 21:31:56
Two different methods sound most semantically clea
|
+ } |
+ |
+ // Fill the data table with undefined. |
+ HValue* undefined = graph()->GetConstantUndefined(); |
+ for (int i = kDataTableStartIndex; i < kInitialFixedArrayLength; ++i) { |
+ Add<HStoreKeyed>(table, Add<HConstant>(i), undefined, FAST_ELEMENTS); |
Dmitry Lomov (no reviews)
2014/12/09 20:48:51
Ditto.
|
+ } |
+ |
+ return table; |
+} |
+ |
+ |
+void HOptimizedGraphBuilder::GenerateSetInitialize(CallRuntime* call) { |
+ DCHECK(call->arguments()->length() == 1); |
+ CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
+ HValue* receiver = Pop(); |
+ |
+ NoObservableSideEffectsScope no_effects(this); |
+ HValue* table = BuildAllocateOrderedHashTable<OrderedHashSet>(); |
+ Add<HStoreNamedField>(receiver, HObjectAccess::ForJSCollectionTable(), table); |
+ return ast_context()->ReturnValue(receiver); |
+} |
+ |
+ |
+void HOptimizedGraphBuilder::GenerateMapInitialize(CallRuntime* call) { |
+ DCHECK(call->arguments()->length() == 1); |
+ CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
+ HValue* receiver = Pop(); |
+ |
+ NoObservableSideEffectsScope no_effects(this); |
+ HValue* table = BuildAllocateOrderedHashTable<OrderedHashMap>(); |
+ Add<HStoreNamedField>(receiver, HObjectAccess::ForJSCollectionTable(), table); |
+ return ast_context()->ReturnValue(receiver); |
+} |
+ |
+ |
void HOptimizedGraphBuilder::GenerateGetCachedArrayIndex(CallRuntime* call) { |
DCHECK(call->arguments()->length() == 1); |
CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |