diff --git a/src/elements.cc b/src/elements.cc index 2b0e696e72..2739b0c635 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -1385,13 +1385,12 @@ class DictionaryElementsAccessor DisallowHeapAllocation no_gc; // Remove elements that should be deleted. int removed_entries = 0; - Handle the_hole_value = isolate->factory()->the_hole_value(); for (int entry = 0; entry < capacity; entry++) { Object* index = dict->KeyAt(entry); if (index->IsNumber()) { uint32_t number = static_cast(index->Number()); if (length <= number && number < old_length) { - dict->SetEntry(entry, the_hole_value, the_hole_value); + dict->ClearEntry(entry); removed_entries++; } } diff --git a/src/lookup.cc b/src/lookup.cc index 68453d7e2d..5fef726d7a 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -304,7 +304,7 @@ void LookupIterator::ReconfigureDataProperty(Handle value, int enumeration_index = original_details.dictionary_index(); DCHECK(enumeration_index > 0); details = details.set_index(enumeration_index); - dictionary->SetEntry(dictionary_entry(), name(), value, details); + dictionary->SetEntry(dictionary_entry(), *name(), *value, details); property_details_ = details; } state_ = DATA; diff --git a/src/objects-inl.h b/src/objects-inl.h index d64872a442..c41162d487 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6043,51 +6043,22 @@ bool AccessorPair::IsJSAccessor(Object* obj) { } template -void Dictionary::SetEntry(int entry, Handle key, - Handle value) { - this->SetEntry(entry, key, value, PropertyDetails(Smi::kZero)); +void Dictionary::ClearEntry(int entry) { + Object* the_hole = this->GetHeap()->the_hole_value(); + SetEntry(entry, the_hole, the_hole, PropertyDetails::Empty()); } template -void Dictionary::SetEntry(int entry, Handle key, - Handle value, +void Dictionary::SetEntry(int entry, Object* key, Object* value, PropertyDetails details) { - Shape::SetEntry(static_cast(this), entry, key, value, details); -} - - -template -template -void BaseDictionaryShape::SetEntry(Dictionary* dict, int entry, - Handle key, - Handle value, - PropertyDetails details) { STATIC_ASSERT(Dictionary::kEntrySize == 2 || Dictionary::kEntrySize == 3); DCHECK(!key->IsName() || details.dictionary_index() > 0); - int index = dict->EntryToIndex(entry); + int index = DerivedHashTable::EntryToIndex(entry); DisallowHeapAllocation no_gc; - WriteBarrierMode mode = dict->GetWriteBarrierMode(no_gc); - dict->set(index + Dictionary::kEntryKeyIndex, *key, mode); - dict->set(index + Dictionary::kEntryValueIndex, *value, mode); - if (Dictionary::kEntrySize == 3) { - dict->set(index + Dictionary::kEntryDetailsIndex, details.AsSmi()); - } -} - - -template -void GlobalDictionaryShape::SetEntry(Dictionary* dict, int entry, - Handle key, Handle value, - PropertyDetails details) { - STATIC_ASSERT(Dictionary::kEntrySize == 2); - DCHECK(!key->IsName() || details.dictionary_index() > 0); - DCHECK(value->IsPropertyCell()); - int index = dict->EntryToIndex(entry); - DisallowHeapAllocation no_gc; - WriteBarrierMode mode = dict->GetWriteBarrierMode(no_gc); - dict->set(index + Dictionary::kEntryKeyIndex, *key, mode); - dict->set(index + Dictionary::kEntryValueIndex, *value, mode); - PropertyCell::cast(*value)->set_property_details(details); + WriteBarrierMode mode = this->GetWriteBarrierMode(no_gc); + this->set(index + Derived::kEntryKeyIndex, key, mode); + this->set(index + Derived::kEntryValueIndex, value, mode); + if (Shape::kHasDetails) DetailsAtPut(entry, details); } @@ -6152,7 +6123,7 @@ Handle NameDictionaryShape::AsHandle(Isolate* isolate, template PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) { - DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). + DCHECK_LE(0, entry); // Not found is -1, which is not caught by get(). Object* raw_value = dict->ValueAt(entry); DCHECK(raw_value->IsPropertyCell()); PropertyCell* cell = PropertyCell::cast(raw_value); @@ -6163,10 +6134,8 @@ PropertyDetails GlobalDictionaryShape::DetailsAt(Dictionary* dict, int entry) { template void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry, PropertyDetails value) { - DCHECK(entry >= 0); // Not found is -1, which is not caught by get(). - Object* raw_value = dict->ValueAt(entry); - DCHECK(raw_value->IsPropertyCell()); - PropertyCell* cell = PropertyCell::cast(raw_value); + DCHECK_LE(0, entry); // Not found is -1, which is not caught by get(). + PropertyCell* cell = PropertyCell::cast(dict->ValueAt(entry)); if (cell->property_details().IsReadOnly() != value.IsReadOnly()) { cell->dependent_code()->DeoptimizeDependentCodeGroup( cell->GetIsolate(), DependentCode::kPropertyCellChangedGroup); @@ -6174,7 +6143,6 @@ void GlobalDictionaryShape::DetailsAtPut(Dictionary* dict, int entry, cell->set_property_details(value); } - template bool GlobalDictionaryShape::IsDeleted(Dictionary* dict, int entry) { DCHECK(dict->ValueAt(entry)->IsPropertyCell()); diff --git a/src/objects.cc b/src/objects.cc index d8ebe796e1..1f9e55c828 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -1953,7 +1953,7 @@ void JSObject::SetNormalizedProperty(Handle object, int enumeration_index = original_details.dictionary_index(); DCHECK(enumeration_index > 0); details = details.set_index(enumeration_index); - dictionary->SetEntry(entry, name, value, details); + dictionary->SetEntry(entry, *name, *value, details); } } } @@ -17570,11 +17570,9 @@ Handle BaseNameDictionary::EnsureCapacity( template Handle Dictionary::DeleteEntry( Handle dictionary, int entry) { - Factory* factory = dictionary->GetIsolate()->factory(); DCHECK(Shape::kEntrySize != 3 || dictionary->DetailsAt(entry).IsConfigurable()); - dictionary->SetEntry( - entry, factory->the_hole_value(), factory->the_hole_value()); + dictionary->ClearEntry(entry); dictionary->ElementRemoved(); return Shrink(dictionary); } @@ -17627,7 +17625,7 @@ Handle Dictionary::Add(Handle dictionary, Handle k = Shape::AsHandle(isolate, key); uint32_t entry = dictionary->FindInsertionEntry(hash); - dictionary->SetEntry(entry, k, value, details); + dictionary->SetEntry(entry, *k, *value, details); DCHECK(dictionary->KeyAt(entry)->IsNumber() || dictionary->KeyAt(entry)->IsUniqueName()); dictionary->ElementAdded(); diff --git a/src/objects/dictionary.h b/src/objects/dictionary.h index 69df0c4312..f600133eba 100644 --- a/src/objects/dictionary.h +++ b/src/objects/dictionary.h @@ -74,8 +74,8 @@ class Dictionary : public HashTable { Object* SlowReverseLookup(Object* value); // Sets the entry to (key, value) pair. - inline void SetEntry(int entry, Handle key, Handle value); - inline void SetEntry(int entry, Handle key, Handle value, + inline void ClearEntry(int entry); + inline void SetEntry(int entry, Object* key, Object* value, PropertyDetails details); MUST_USE_RESULT static Handle Add(Handle dictionary, @@ -93,6 +93,7 @@ class Dictionary : public HashTable { template class BaseDictionaryShape : public BaseShape { public: + static const bool kHasDetails = true; template static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) { STATIC_ASSERT(Dictionary::kEntrySize == 3); @@ -113,10 +114,6 @@ class BaseDictionaryShape : public BaseShape { static bool IsDeleted(Dictionary* dict, int entry) { return false; } - - template - static inline void SetEntry(Dictionary* dict, int entry, Handle key, - Handle value, PropertyDetails details); }; class NameDictionaryShape : public BaseDictionaryShape> { @@ -200,10 +197,6 @@ class GlobalDictionaryShape : public NameDictionaryShape { template static bool IsDeleted(Dictionary* dict, int entry); - - template - static inline void SetEntry(Dictionary* dict, int entry, Handle key, - Handle value, PropertyDetails details); }; class GlobalDictionary @@ -231,6 +224,7 @@ class SeededNumberDictionaryShape : public NumberDictionaryShape { class UnseededNumberDictionaryShape : public NumberDictionaryShape { public: + static const bool kHasDetails = false; static const int kPrefixSize = 0; static const int kEntrySize = 2;