From a5bde585318fe0fedbe26ddee00400bde9d22ade Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Fri, 25 Apr 2014 13:21:16 +0000 Subject: [PATCH] Dictionary::SetEntry() and Dictionary::AddEntry() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/250913003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20981 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/elements.cc | 2 +- src/objects-inl.h | 14 ++++++------- src/objects.cc | 63 +++++++++++++++++-------------------------------------- src/objects.h | 28 ++++++++++++------------- 4 files changed, 41 insertions(+), 66 deletions(-) diff --git a/src/elements.cc b/src/elements.cc index 9f83122..79dc722 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -1467,7 +1467,7 @@ class DictionaryElementsAccessor DisallowHeapAllocation no_gc; // Remove elements that should be deleted. int removed_entries = 0; - Object* the_hole_value = isolate->heap()->the_hole_value(); + Handle the_hole_value = isolate->factory()->the_hole_value(); for (int i = 0; i < capacity; i++) { Object* key = dict->KeyAt(i); if (key->IsNumber()) { diff --git a/src/objects-inl.h b/src/objects-inl.h index 9238d3c..6537251 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6586,16 +6586,16 @@ bool AccessorPair::prohibits_overwriting() { template void Dictionary::SetEntry(int entry, - Object* key, - Object* value) { + Handle key, + Handle value) { SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); } template void Dictionary::SetEntry(int entry, - Object* key, - Object* value, + Handle key, + Handle value, PropertyDetails details) { ASSERT(!key->IsName() || details.IsDeleted() || @@ -6603,8 +6603,8 @@ void Dictionary::SetEntry(int entry, int index = DerivedHashTable::EntryToIndex(entry); DisallowHeapAllocation no_gc; WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc); - FixedArray::set(index, key, mode); - FixedArray::set(index+1, value, mode); + FixedArray::set(index, *key, mode); + FixedArray::set(index+1, *value, mode); FixedArray::set(index+2, details.AsSmi()); } @@ -6705,7 +6705,7 @@ MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) { Handle ObjectHashTable::Shrink( Handle table, Handle key) { - return HashTable_::Shrink(table, *key); + return DerivedHashTable::Shrink(table, *key); } diff --git a/src/objects.cc b/src/objects.cc index 52b9680..6f7315e 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -692,7 +692,7 @@ void JSObject::SetNormalizedProperty(Handle object, // Please note we have to update the property details. property_dictionary->DetailsAtPut(entry, details); } else { - property_dictionary->SetEntry(entry, *name, *value, details); + property_dictionary->SetEntry(entry, name, value, details); } } @@ -1932,7 +1932,7 @@ void JSObject::AddSlowProperty(Handle object, int index = dict->NextEnumerationIndex(); PropertyDetails details = PropertyDetails(attributes, NORMAL, index); dict->SetNextEnumerationIndex(index + 1); - dict->SetEntry(entry, *name, *cell, details); + dict->SetEntry(entry, name, cell, details); return; } Handle cell = isolate->factory()->NewPropertyCell(value); @@ -14980,18 +14980,6 @@ template Handle Dictionary >:: EnsureCapacity(Handle, int, Handle); -template MaybeObject* -Dictionary:: - AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); - -template MaybeObject* -Dictionary:: - AddEntry(uint32_t, Object*, PropertyDetails, uint32_t); - -template MaybeObject* -Dictionary >::AddEntry( - Handle, Object*, PropertyDetails, uint32_t); - template int Dictionary:: NumberOfEnumElements(); @@ -15840,8 +15828,9 @@ Handle Dictionary::DeleteProperty( if (details.IsDontDelete() && mode != JSReceiver::FORCE_DELETION) { return factory->false_value(); } + dictionary->SetEntry( - entry, *factory->the_hole_value(), *factory->the_hole_value()); + entry, factory->the_hole_value(), factory->the_hole_value()); dictionary->ElementRemoved(); return factory->true_value(); } @@ -15866,7 +15855,8 @@ Handle Dictionary::AtPut( USE(k); PropertyDetails details = PropertyDetails(NONE, NORMAL, 0); - return AddEntry(dictionary, key, value, details, dictionary->Hash(key)); + AddEntry(dictionary, key, value, details, dictionary->Hash(key)); + return dictionary; } @@ -15881,52 +15871,37 @@ Handle Dictionary::Add( // Check whether the dictionary should be extended. dictionary = EnsureCapacity(dictionary, 1, key); - return AddEntry(dictionary, key, value, details, dictionary->Hash(key)); + AddEntry(dictionary, key, value, details, dictionary->Hash(key)); + return dictionary; } // Add a key, value pair to the dictionary. template -Handle Dictionary::AddEntry( +void Dictionary::AddEntry( Handle dictionary, Key key, Handle value, PropertyDetails details, uint32_t hash) { - CALL_HEAP_FUNCTION( - dictionary->GetIsolate(), - dictionary->AddEntry(key, *value, details, hash), - Derived); -} - -template -MaybeObject* Dictionary::AddEntry( - Key key, - Object* value, - PropertyDetails details, - uint32_t hash) { // Compute the key object. - Object* k; - { MaybeObject* maybe_k = Shape::AsObject(this->GetHeap(), key); - if (!maybe_k->ToObject(&k)) return maybe_k; - } + Handle k = Shape::AsHandle(dictionary->GetIsolate(), key); - uint32_t entry = Dictionary::FindInsertionEntry(hash); + uint32_t entry = dictionary->FindInsertionEntry(hash); // Insert element at empty or deleted entry if (!details.IsDeleted() && details.dictionary_index() == 0 && Shape::kIsEnumerable) { // Assign an enumeration index to the property and update // SetNextEnumerationIndex. - int index = NextEnumerationIndex(); + int index = dictionary->NextEnumerationIndex(); details = PropertyDetails(details.attributes(), details.type(), index); - SetNextEnumerationIndex(index + 1); + dictionary->SetNextEnumerationIndex(index + 1); } - SetEntry(entry, k, value, details); - ASSERT((Dictionary::KeyAt(entry)->IsNumber() || - Dictionary::KeyAt(entry)->IsName())); - DerivedHashTable::ElementAdded(); - return this; + dictionary->SetEntry(entry, k, value, details); + ASSERT((dictionary->KeyAt(entry)->IsNumber() || + dictionary->KeyAt(entry)->IsName())); + dictionary->ElementAdded(); } @@ -16002,7 +15977,7 @@ Handle SeededNumberDictionary::Set( dictionary->DetailsAt(entry).dictionary_index()); Handle object_key = SeededNumberDictionaryShape::AsHandle(dictionary->GetIsolate(), key); - dictionary->SetEntry(entry, *object_key, *value, details); + dictionary->SetEntry(entry, object_key, value, details); return dictionary; } @@ -16015,7 +15990,7 @@ Handle UnseededNumberDictionary::Set( if (entry == kNotFound) return AddNumberEntry(dictionary, key, value); Handle object_key = UnseededNumberDictionaryShape::AsHandle(dictionary->GetIsolate(), key); - dictionary->SetEntry(entry, *object_key, *value); + dictionary->SetEntry(entry, object_key, value); return dictionary; } diff --git a/src/objects.h b/src/objects.h index 2970c88..067cf45 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3822,7 +3822,7 @@ class HashTable: public FixedArray { } // Attempt to shrink hash table after removal of key. - static Handle Shrink(Handle table, Key key); + MUST_USE_RESULT static Handle Shrink(Handle table, Key key); // Ensure enough space for n additional elements. MUST_USE_RESULT static Handle EnsureCapacity( @@ -3998,7 +3998,9 @@ class Dictionary: public HashTable { JSObject::DeleteMode mode); // Attempt to shrink the dictionary after deletion of key. - static inline Handle Shrink(Handle dictionary, Key key) { + MUST_USE_RESULT static inline Handle Shrink( + Handle dictionary, + Key key) { return DerivedHashTable::Shrink(dictionary, key); } @@ -4047,11 +4049,11 @@ class Dictionary: public HashTable { // Sets the entry to (key, value) pair. inline void SetEntry(int entry, - Object* key, - Object* value); + Handle key, + Handle value); inline void SetEntry(int entry, - Object* key, - Object* value, + Handle key, + Handle value, PropertyDetails details); MUST_USE_RESULT static Handle Add( @@ -4068,11 +4070,7 @@ class Dictionary: public HashTable { Handle value); // Add entry to dictionary. - MUST_USE_RESULT MaybeObject* AddEntry(Key key, - Object* value, - PropertyDetails details, - uint32_t hash); - MUST_USE_RESULT static Handle AddEntry( + static void AddEntry( Handle dictionary, Key key, Handle value, @@ -4256,7 +4254,8 @@ class ObjectHashTableShape : public BaseShape { class ObjectHashTable: public HashTable { - typedef HashTable HashTable_; + typedef HashTable< + ObjectHashTable, ObjectHashTableShape, Object*> DerivedHashTable; public: static inline ObjectHashTable* cast(Object* obj) { ASSERT(obj->IsHashTable()); @@ -4264,8 +4263,9 @@ class ObjectHashTable: public HashTable Shrink(Handle table, - Handle key); + MUST_USE_RESULT static inline Handle Shrink( + Handle table, + Handle key); // Looks up the value associated with the given key. The hole value is // returned in case the key is not present. -- 2.7.4