From f86232836e661201cc25d894ad084b48f9f70ff9 Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Thu, 24 Apr 2014 15:33:40 +0000 Subject: [PATCH] Dictionary::GenerateNewEnumerationIndices() and Dictionary::EnsureCapacity() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/250013002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20950 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects-inl.h | 6 ++++ src/objects.cc | 91 ++++++++++++++++++++----------------------------------- src/objects.h | 9 +++--- 3 files changed, 44 insertions(+), 62 deletions(-) diff --git a/src/objects-inl.h b/src/objects-inl.h index 741621e..76a43d5 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6679,6 +6679,12 @@ Handle NameDictionaryShape::AsHandle(Isolate* isolate, } +void NameDictionary::DoGenerateNewEnumerationIndices( + Handle dictionary) { + DerivedDictionary::GenerateNewEnumerationIndices(dictionary); +} + + bool ObjectHashTableShape::IsMatch(Object* key, Object* other) { return key->SameValue(other); } diff --git a/src/objects.cc b/src/objects.cc index 57bcf84..1089c15 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -14818,9 +14818,10 @@ Handle HashTable::EnsureCapacity( Key key, PretenureFlag pretenure) { Isolate* isolate = table->GetIsolate(); - CALL_HEAP_FUNCTION(isolate, - table->EnsureCapacity(n, key, pretenure), - Derived); + CALL_HEAP_FUNCTION( + isolate, + static_cast(*table)->EnsureCapacity(n, key, pretenure), + Derived); } @@ -14992,9 +14993,9 @@ template Handle Dictionary >::Add( Handle, Handle, Handle, PropertyDetails); -template MaybeObject* +template void Dictionary >:: - GenerateNewEnumerationIndices(); + GenerateNewEnumerationIndices(Handle); template int Dictionary:: @@ -15014,17 +15015,17 @@ Dictionary:: Handle, PropertyDetails); -template MaybeObject* +template Handle Dictionary:: - EnsureCapacity(int, uint32_t); + EnsureCapacity(Handle, int, uint32_t); -template MaybeObject* +template Handle Dictionary:: - EnsureCapacity(int, uint32_t); + EnsureCapacity(Handle, int, uint32_t); -template MaybeObject* +template Handle Dictionary >:: - EnsureCapacity(int, Handle); + EnsureCapacity(Handle, int, Handle); template MaybeObject* Dictionary:: @@ -15829,46 +15830,33 @@ Handle Dictionary::New( } - -void NameDictionary::DoGenerateNewEnumerationIndices( - Handle dictionary) { - CALL_HEAP_FUNCTION_VOID(dictionary->GetIsolate(), - dictionary->GenerateNewEnumerationIndices()); -} - template -MaybeObject* Dictionary::GenerateNewEnumerationIndices() { - Heap* heap = Dictionary::GetHeap(); - int length = DerivedHashTable::NumberOfElements(); +void Dictionary::GenerateNewEnumerationIndices( + Handle dictionary) { + Factory* factory = dictionary->GetIsolate()->factory(); + int length = dictionary->NumberOfElements(); // Allocate and initialize iteration order array. - Object* obj; - { MaybeObject* maybe_obj = heap->AllocateFixedArray(length); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } - FixedArray* iteration_order = FixedArray::cast(obj); + Handle iteration_order = factory->NewFixedArray(length); for (int i = 0; i < length; i++) { iteration_order->set(i, Smi::FromInt(i)); } // Allocate array with enumeration order. - { MaybeObject* maybe_obj = heap->AllocateFixedArray(length); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } - FixedArray* enumeration_order = FixedArray::cast(obj); + Handle enumeration_order = factory->NewFixedArray(length); // Fill the enumeration order array with property details. - int capacity = DerivedHashTable::Capacity(); + int capacity = dictionary->Capacity(); int pos = 0; for (int i = 0; i < capacity; i++) { - if (Dictionary::IsKey(Dictionary::KeyAt(i))) { - int index = DetailsAt(i).dictionary_index(); + if (dictionary->IsKey(dictionary->KeyAt(i))) { + int index = dictionary->DetailsAt(i).dictionary_index(); enumeration_order->set(pos++, Smi::FromInt(index)); } } // Sort the arrays wrt. enumeration order. - iteration_order->SortPairs(enumeration_order, enumeration_order->length()); + iteration_order->SortPairs(*enumeration_order, enumeration_order->length()); // Overwrite the enumeration_order with the enumeration indices. for (int i = 0; i < length; i++) { @@ -15878,46 +15866,33 @@ MaybeObject* Dictionary::GenerateNewEnumerationIndices() { } // Update the dictionary with new indices. - capacity = DerivedHashTable::Capacity(); + capacity = dictionary->Capacity(); pos = 0; for (int i = 0; i < capacity; i++) { - if (Dictionary::IsKey(Dictionary::KeyAt(i))) { + if (dictionary->IsKey(dictionary->KeyAt(i))) { int enum_index = Smi::cast(enumeration_order->get(pos++))->value(); - PropertyDetails details = DetailsAt(i); + PropertyDetails details = dictionary->DetailsAt(i); PropertyDetails new_details = PropertyDetails( details.attributes(), details.type(), enum_index); - DetailsAtPut(i, new_details); + dictionary->DetailsAtPut(i, new_details); } } // Set the next enumeration index. - SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length); - return this; + dictionary->SetNextEnumerationIndex(PropertyDetails::kInitialIndex+length); } + template -MaybeObject* Dictionary::EnsureCapacity(int n, Key key) { +Handle Dictionary::EnsureCapacity( + Handle dictionary, int n, Key key) { // Check whether there are enough enumeration indices to add n elements. if (Shape::kIsEnumerable && - !PropertyDetails::IsValidIndex(NextEnumerationIndex() + n)) { + !PropertyDetails::IsValidIndex(dictionary->NextEnumerationIndex() + n)) { // If not, we generate new indices for the properties. - Object* result; - { MaybeObject* maybe_result = GenerateNewEnumerationIndices(); - if (!maybe_result->ToObject(&result)) return maybe_result; - } + GenerateNewEnumerationIndices(dictionary); } - return DerivedHashTable::EnsureCapacity(n, key); -} - - - -template -Handle Dictionary::EnsureCapacity( - Handle obj, int n, Key key) { - Isolate* isolate = obj->GetIsolate(); - CALL_HEAP_FUNCTION(isolate, - obj->EnsureCapacity(n, key), - Derived); + return DerivedHashTable::EnsureCapacity(dictionary, n, key); } diff --git a/src/objects.h b/src/objects.h index bb4891f..e313d88 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4070,8 +4070,6 @@ class Dictionary: public HashTable { PretenureFlag pretenure = NOT_TENURED); // Ensure enough space for n additional elements. - MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); - static Handle EnsureCapacity(Handle obj, int n, Key key); #ifdef OBJECT_PRINT @@ -4115,7 +4113,7 @@ class Dictionary: public HashTable { uint32_t hash); // Generate new enumeration indices to avoid enumeration index overflow. - MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); + static void GenerateNewEnumerationIndices(Handle dictionary); static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex; static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; }; @@ -4138,6 +4136,9 @@ class NameDictionaryShape : public BaseShape > { class NameDictionary: public Dictionary > { + typedef Dictionary< + NameDictionary, NameDictionaryShape, Handle > DerivedDictionary; + public: static inline NameDictionary* cast(Object* obj) { ASSERT(obj->IsDictionary()); @@ -4146,7 +4147,7 @@ class NameDictionary: public Dictionary dictionary); // Find entry for key, otherwise return kNotFound. Optimized version of -- 2.7.4