Index: src/hydrogen.cc |
diff --git a/src/hydrogen.cc b/src/hydrogen.cc |
index 5947643733d67e6835047cc3eb5f6a3d799a980b..9114100d442cdbdf42801a573467b4d6a5acf236 100644 |
--- a/src/hydrogen.cc |
+++ b/src/hydrogen.cc |
@@ -12648,6 +12648,61 @@ void HOptimizedGraphBuilder::GenerateMapGetSize(CallRuntime* call) { |
} |
+template <typename CollectionType> |
+HValue* HOptimizedGraphBuilder::BuildAllocateOrderedHashTable() { |
+ static const int kInitialCapacity = CollectionType::kMinCapacity; |
+ static const int kInitialNumBuckets = |
+ kInitialCapacity / CollectionType::kLoadFactor; |
+ HValue* size = Add<HConstant>( |
+ FixedArray::kHeaderSize + CollectionType::kHashTableStartIndex + |
+ kInitialNumBuckets + (kInitialCapacity * CollectionType::kEntrySize)); |
+ HValue* table = |
+ Add<HAllocate>(size, HType::HeapObject(), NOT_TENURED, FIXED_ARRAY_TYPE); |
adamk
2014/12/08 21:41:14
One question about HAllocate: do I need to add cod
Dmitry Lomov (no reviews)
2014/12/09 12:05:39
Yes. See HOGB::BuildAllocateFixedTypedArray for in
adamk
2014/12/09 19:24:23
Added a bunch of proper initialization. Now the co
|
+ Add<HStoreNamedField>( |
+ table, HObjectAccess::ForMap(), |
+ Add<HConstant>(isolate()->factory()->ordered_hash_table_map())); |
+ HValue* not_found = Add<HConstant>(CollectionType::kNotFound); |
+ for (int i = 0; i < kInitialNumBuckets; ++i) { |
+ Add<HStoreKeyed>(table, |
+ Add<HConstant>(CollectionType::kHashTableStartIndex + i), |
+ not_found, FAST_ELEMENTS); |
+ } |
+ 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()); |
+ return table; |
+} |
+ |
+ |
+void HOptimizedGraphBuilder::GenerateSetInitialize(CallRuntime* call) { |
+ DCHECK(call->arguments()->length() == 1); |
+ CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
+ HValue* receiver = Pop(); |
+ 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(); |
+ 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))); |