From aa470e0af0e5aca930ddc38ed8cbe098440e07cc Mon Sep 17 00:00:00 2001 From: ishell Date: Mon, 1 Jun 2015 10:07:25 -0700 Subject: [PATCH] Enum DictionaryEntryType removed. Dictionary customization should be implemented in respective shape class. Review URL: https://codereview.chromium.org/1160813009 Cr-Commit-Position: refs/heads/master@{#28738} --- src/objects-inl.h | 7 +++ src/objects.cc | 100 ++++++++++++++++--------------------------- src/objects.h | 84 +++++++++--------------------------- src/runtime/runtime-array.cc | 3 +- 4 files changed, 65 insertions(+), 129 deletions(-) diff --git a/src/objects-inl.h b/src/objects-inl.h index 0c61686..12e3048 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -7210,6 +7210,13 @@ Handle NameDictionary::DoGenerateNewEnumerationIndices( } +template +bool GlobalDictionaryShape::IsDeleted(Dictionary* dict, int entry) { + DCHECK(dict->ValueAt(entry)->IsPropertyCell()); + return PropertyCell::cast(dict->ValueAt(entry))->value()->IsTheHole(); +} + + bool ObjectHashTableShape::IsMatch(Handle key, Object* other) { return key->SameValue(other); } diff --git a/src/objects.cc b/src/objects.cc index 0ea8ffb..f4112d3 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -6384,21 +6384,21 @@ Handle JSObject::GetEnumPropertyKeys(Handle object, return storage; } else if (object->IsGlobalObject()) { Handle dictionary(object->global_dictionary()); - int length = dictionary->NumberOfEnumElements(*object); + int length = dictionary->NumberOfEnumElements(); if (length == 0) { return Handle(isolate->heap()->empty_fixed_array()); } Handle storage = isolate->factory()->NewFixedArray(length); - dictionary->CopyEnumKeysTo(*object, *storage); + dictionary->CopyEnumKeysTo(*storage); return storage; } else { Handle dictionary(object->property_dictionary()); - int length = dictionary->NumberOfEnumElements(*object); + int length = dictionary->NumberOfEnumElements(); if (length == 0) { return Handle(isolate->heap()->empty_fixed_array()); } Handle storage = isolate->factory()->NewFixedArray(length); - dictionary->CopyEnumKeysTo(*object, *storage); + dictionary->CopyEnumKeysTo(*storage); return storage; } } @@ -14063,7 +14063,8 @@ void Dictionary::Print(std::ostream& os) { // NOLINT } else { os << Brief(k); } - os << ": " << Brief(ValueAt(i)) << " " << DetailsAt(i) << "\n"; + os << ": " << Brief(this->ValueAt(i)) << " " << this->DetailsAt(i) + << "\n"; } } } @@ -14079,7 +14080,7 @@ void Dictionary::CopyValuesTo(FixedArray* elements) { for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k)) { - elements->set(pos++, ValueAt(i), mode); + elements->set(pos++, this->ValueAt(i), mode); } } DCHECK(pos == elements->length()); @@ -14254,10 +14255,9 @@ int JSObject::NumberOfOwnProperties(PropertyAttributes filter) { } return map->NumberOfDescribedProperties(OWN_DESCRIPTORS, filter); } else if (IsGlobalObject()) { - return global_dictionary()->NumberOfElementsFilterAttributes(this, filter); + return global_dictionary()->NumberOfElementsFilterAttributes(filter); } else { - return property_dictionary()->NumberOfElementsFilterAttributes(this, - filter); + return property_dictionary()->NumberOfElementsFilterAttributes(filter); } } @@ -14391,10 +14391,10 @@ void JSObject::GetOwnPropertyNames( } } } else if (IsGlobalObject()) { - global_dictionary()->CopyKeysTo(this, storage, index, filter, + global_dictionary()->CopyKeysTo(storage, index, filter, GlobalDictionary::UNSORTED); } else { - property_dictionary()->CopyKeysTo(this, storage, index, filter, + property_dictionary()->CopyKeysTo(storage, index, filter, NameDictionary::UNSORTED); } } @@ -14478,13 +14478,10 @@ int JSObject::GetOwnElementKeys(FixedArray* storage, case DICTIONARY_ELEMENTS: { if (storage != NULL) { - element_dictionary()->CopyKeysTo( - storage, filter, SeededNumberDictionary::SORTED); + element_dictionary()->CopyKeysTo(storage, filter, + SeededNumberDictionary::SORTED); } - counter += - element_dictionary() - ->NumberOfElementsFilterAttributes( - filter); + counter += element_dictionary()->NumberOfElementsFilterAttributes(filter); break; } case SLOPPY_ARGUMENTS_ELEMENTS: { @@ -14497,11 +14494,10 @@ int JSObject::GetOwnElementKeys(FixedArray* storage, SeededNumberDictionary* dictionary = SeededNumberDictionary::cast(arguments); if (storage != NULL) { - dictionary->CopyKeysTo( - storage, filter, SeededNumberDictionary::UNSORTED); + dictionary->CopyKeysTo(storage, filter, + SeededNumberDictionary::UNSORTED); } - counter += dictionary->NumberOfElementsFilterAttributes< - DictionaryEntryType::kObjects>(filter); + counter += dictionary->NumberOfElementsFilterAttributes(filter); for (int i = 0; i < mapped_length; ++i) { if (!parameter_map->get(i + 2)->IsTheHole()) { if (storage != NULL) storage->set(counter, Smi::FromInt(i)); @@ -15166,13 +15162,8 @@ template Handle Dictionary >:: EnsureCapacity(Handle, int, Handle); -template bool -Dictionary::HasComplexElements(); - -template bool -Dictionary::HasComplexElements(); +template bool Dictionary::HasComplexElements(); template int HashTable::FindEntry(uint32_t); @@ -16252,22 +16243,7 @@ Handle UnseededNumberDictionary::Set( } -template -static inline bool IsDeleted(D d, int i) { - switch (type) { - case DictionaryEntryType::kObjects: - return false; - case DictionaryEntryType::kCells: - DCHECK(d->ValueAt(i)->IsPropertyCell()); - return PropertyCell::cast(d->ValueAt(i))->value()->IsTheHole(); - } - UNREACHABLE(); - return false; -} - - template -template int Dictionary::NumberOfElementsFilterAttributes( PropertyAttributes filter) { int capacity = this->Capacity(); @@ -16275,8 +16251,8 @@ int Dictionary::NumberOfElementsFilterAttributes( for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k) && !FilterKey(k, filter)) { - if (IsDeleted(this, i)) continue; - PropertyDetails details = DetailsAt(i); + if (this->IsDeleted(i)) continue; + PropertyDetails details = this->DetailsAt(i); PropertyAttributes attr = details.attributes(); if ((attr & filter) == 0) result++; } @@ -16286,14 +16262,13 @@ int Dictionary::NumberOfElementsFilterAttributes( template -template bool Dictionary::HasComplexElements() { int capacity = this->Capacity(); for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k) && !FilterKey(k, NONE)) { - if (IsDeleted(this, i)) continue; - PropertyDetails details = DetailsAt(i); + if (this->IsDeleted(i)) continue; + PropertyDetails details = this->DetailsAt(i); if (details.type() == ACCESSOR_CONSTANT) return true; PropertyAttributes attr = details.attributes(); if (attr & (READ_ONLY | DONT_DELETE | DONT_ENUM)) return true; @@ -16304,18 +16279,17 @@ bool Dictionary::HasComplexElements() { template -template void Dictionary::CopyKeysTo( FixedArray* storage, PropertyAttributes filter, typename Dictionary::SortMode sort_mode) { - DCHECK(storage->length() >= NumberOfElementsFilterAttributes(filter)); + DCHECK(storage->length() >= NumberOfElementsFilterAttributes(filter)); int capacity = this->Capacity(); int index = 0; for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k) && !FilterKey(k, filter)) { - if (IsDeleted(this, i)) continue; - PropertyDetails details = DetailsAt(i); + if (this->IsDeleted(i)) continue; + PropertyDetails details = this->DetailsAt(i); PropertyAttributes attr = details.attributes(); if ((attr & filter) == 0) storage->set(index++, k); } @@ -16340,7 +16314,6 @@ struct EnumIndexComparator { template -template void Dictionary::CopyEnumKeysTo(FixedArray* storage) { int length = storage->length(); int capacity = this->Capacity(); @@ -16348,12 +16321,12 @@ void Dictionary::CopyEnumKeysTo(FixedArray* storage) { for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k) && !k->IsSymbol()) { - PropertyDetails details = DetailsAt(i); - if (details.IsDontEnum() || IsDeleted(this, i)) continue; - storage->set(properties, Smi::FromInt(i)); - properties++; - if (properties == length) break; - } + PropertyDetails details = this->DetailsAt(i); + if (details.IsDontEnum() || this->IsDeleted(i)) continue; + storage->set(properties, Smi::FromInt(i)); + properties++; + if (properties == length) break; + } } CHECK_EQ(length, properties); EnumIndexComparator cmp(static_cast(this)); @@ -16367,17 +16340,16 @@ void Dictionary::CopyEnumKeysTo(FixedArray* storage) { template -template void Dictionary::CopyKeysTo( FixedArray* storage, int index, PropertyAttributes filter, typename Dictionary::SortMode sort_mode) { - DCHECK(storage->length() >= NumberOfElementsFilterAttributes(filter)); + DCHECK(storage->length() >= NumberOfElementsFilterAttributes(filter)); int capacity = this->Capacity(); for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k) && !FilterKey(k, filter)) { - if (IsDeleted(this, i)) continue; - PropertyDetails details = DetailsAt(i); + if (this->IsDeleted(i)) continue; + PropertyDetails details = this->DetailsAt(i); PropertyAttributes attr = details.attributes(); if ((attr & filter) == 0) storage->set(index++, k); } @@ -16396,7 +16368,7 @@ Object* Dictionary::SlowReverseLookup(Object* value) { for (int i = 0; i < capacity; i++) { Object* k = this->KeyAt(i); if (this->IsKey(k)) { - Object* e = ValueAt(i); + Object* e = this->ValueAt(i); // TODO(dcarney): this should be templatized. if (e->IsPropertyCell()) { e = PropertyCell::cast(e)->value(); diff --git a/src/objects.h b/src/objects.h index 0cf1ee4..6c177f5 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3598,9 +3598,6 @@ class StringTable: public HashTable class Dictionary: public HashTable { typedef HashTable DerivedHashTable; @@ -3628,6 +3625,11 @@ class Dictionary: public HashTable { this->set(Derived::EntryToIndex(entry) + 2, value.AsSmi()); } + // Returns true if property at given entry is deleted. + bool IsDeleted(int entry) { + return Shape::IsDeleted(static_cast(this), entry); + } + // Delete a property from the dictionary. static Handle DeleteProperty(Handle dictionary, int entry); @@ -3644,87 +3646,30 @@ class Dictionary: public HashTable { // Returns the number of elements in the dictionary filtering out properties // with the specified attributes. - template int NumberOfElementsFilterAttributes(PropertyAttributes filter); - int NumberOfElementsFilterAttributes(Object* holder, - PropertyAttributes filter) { - if (holder->IsGlobalObject()) { - return NumberOfElementsFilterAttributes( - filter); - } else { - return NumberOfElementsFilterAttributes( - filter); - } - } // Returns the number of enumerable elements in the dictionary. - template int NumberOfEnumElements() { - return NumberOfElementsFilterAttributes( + return NumberOfElementsFilterAttributes( static_cast(DONT_ENUM | SYMBOLIC)); } - int NumberOfEnumElements(Object* holder) { - if (holder->IsGlobalObject()) { - return NumberOfEnumElements(); - } else { - return NumberOfEnumElements(); - } - } // Returns true if the dictionary contains any elements that are non-writable, // non-configurable, non-enumerable, or have getters/setters. - template bool HasComplexElements(); - bool HasComplexElements(Object* holder) { - if (holder->IsGlobalObject()) { - return HasComplexElements(); - } else { - return HasComplexElements(); - } - } enum SortMode { UNSORTED, SORTED }; // Copies keys to preallocated fixed array. - template void CopyKeysTo(FixedArray* storage, PropertyAttributes filter, SortMode sort_mode); - void CopyKeysTo(Object* holder, FixedArray* storage, - PropertyAttributes filter, SortMode sort_mode) { - if (holder->IsGlobalObject()) { - return CopyKeysTo(storage, filter, - sort_mode); - } else { - return CopyKeysTo(storage, filter, - sort_mode); - } - } // Fill in details for properties into storage. - template void CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter, SortMode sort_mode); - void CopyKeysTo(Object* holder, FixedArray* storage, int index, - PropertyAttributes filter, SortMode sort_mode) { - if (holder->IsGlobalObject()) { - return CopyKeysTo(storage, index, filter, - sort_mode); - } else { - return CopyKeysTo(storage, index, filter, - sort_mode); - } - } // Copies enumerable keys to preallocated fixed array. - template void CopyEnumKeysTo(FixedArray* storage); - void CopyEnumKeysTo(Object* holder, FixedArray* storage) { - if (holder->IsGlobalObject()) { - return CopyEnumKeysTo(storage); - } else { - return CopyEnumKeysTo(storage); - } - } // Accessors for next enumeration index. void SetNextEnumerationIndex(int index) { @@ -3806,7 +3751,17 @@ class NameDictionaryBase : public Dictionary > { }; -class NameDictionaryShape : public BaseShape > { +template +class BaseDictionaryShape : public BaseShape { + public: + template + static bool IsDeleted(Dictionary* dict, int entry) { + return false; + } +}; + + +class NameDictionaryShape : public BaseDictionaryShape > { public: static inline bool IsMatch(Handle key, Object* other); static inline uint32_t Hash(Handle key); @@ -3834,6 +3789,9 @@ class NameDictionary class GlobalDictionaryShape : public NameDictionaryShape { public: static const int kEntrySize = 3; // Overrides NameDictionaryShape::kEntrySize + + template + static bool IsDeleted(Dictionary* dict, int entry); }; @@ -3844,7 +3802,7 @@ class GlobalDictionary }; -class NumberDictionaryShape : public BaseShape { +class NumberDictionaryShape : public BaseDictionaryShape { public: static inline bool IsMatch(uint32_t key, Object* other); static inline Handle AsHandle(Isolate* isolate, uint32_t key); diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc index cc4a2e7..e2f6d79 100644 --- a/src/runtime/runtime-array.cc +++ b/src/runtime/runtime-array.cc @@ -1293,8 +1293,7 @@ RUNTIME_FUNCTION(Runtime_HasComplexElements) { return isolate->heap()->true_value(); } if (!current->HasDictionaryElements()) continue; - if (current->element_dictionary() - ->HasComplexElements()) { + if (current->element_dictionary()->HasComplexElements()) { return isolate->heap()->true_value(); } } -- 2.7.4