Commit 33f11a1f authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[runtime] Cleanup NumberOfEnumerableProperties

Bug: v8:6474
Also-By: cbruni@chromium.org
Change-Id: I1aefa1156b89a7f8ffafe27e58cacbfecc9a1d02
Reviewed-on: https://chromium-review.googlesource.com/528885Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45814}
parent ac3e4e01
...@@ -3223,8 +3223,7 @@ void MarkCompactCollector::TrimEnumCache(Map* map, ...@@ -3223,8 +3223,7 @@ void MarkCompactCollector::TrimEnumCache(Map* map,
DescriptorArray* descriptors) { DescriptorArray* descriptors) {
int live_enum = map->EnumLength(); int live_enum = map->EnumLength();
if (live_enum == kInvalidEnumCacheSentinel) { if (live_enum == kInvalidEnumCacheSentinel) {
live_enum = live_enum = map->NumberOfEnumerableProperties();
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS);
} }
if (live_enum == 0) return descriptors->ClearEnumCache(); if (live_enum == 0) return descriptors->ClearEnumCache();
......
...@@ -218,11 +218,7 @@ void TrySettingEmptyEnumCache(JSReceiver* object) { ...@@ -218,11 +218,7 @@ void TrySettingEmptyEnumCache(JSReceiver* object) {
DCHECK_EQ(kInvalidEnumCacheSentinel, map->EnumLength()); DCHECK_EQ(kInvalidEnumCacheSentinel, map->EnumLength());
if (!map->OnlyHasSimpleProperties()) return; if (!map->OnlyHasSimpleProperties()) return;
if (map->IsJSProxyMap()) return; if (map->IsJSProxyMap()) return;
if (map->NumberOfOwnDescriptors() > 0) { if (map->NumberOfEnumerableProperties() > 0) return;
int number_of_enumerable_own_properties =
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS);
if (number_of_enumerable_own_properties > 0) return;
}
DCHECK(object->IsJSObject()); DCHECK(object->IsJSObject());
map->SetEnumLength(0); map->SetEnumLength(0);
} }
...@@ -286,12 +282,9 @@ Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate, ...@@ -286,12 +282,9 @@ Handle<FixedArray> GetFastEnumPropertyKeys(Isolate* isolate,
// first step to using the cache is to set the enum length of the map by // first step to using the cache is to set the enum length of the map by
// counting the number of own descriptors that are ENUMERABLE_STRINGS. // counting the number of own descriptors that are ENUMERABLE_STRINGS.
if (own_property_count == kInvalidEnumCacheSentinel) { if (own_property_count == kInvalidEnumCacheSentinel) {
own_property_count = own_property_count = map->NumberOfEnumerableProperties();
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS);
} else { } else {
DCHECK( DCHECK_EQ(own_property_count, map->NumberOfEnumerableProperties());
own_property_count ==
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS));
} }
if (descs->HasEnumCache()) { if (descs->HasEnumCache()) {
...@@ -574,7 +567,7 @@ Handle<FixedArray> GetOwnEnumPropertyDictionaryKeys(Isolate* isolate, ...@@ -574,7 +567,7 @@ Handle<FixedArray> GetOwnEnumPropertyDictionaryKeys(Isolate* isolate,
Handle<JSObject> object, Handle<JSObject> object,
T* raw_dictionary) { T* raw_dictionary) {
Handle<T> dictionary(raw_dictionary, isolate); Handle<T> dictionary(raw_dictionary, isolate);
int length = dictionary->NumberOfEnumElements(); int length = dictionary->NumberOfEnumerableProperties();
if (length == 0) { if (length == 0) {
return isolate->factory()->empty_fixed_array(); return isolate->factory()->empty_fixed_array();
} }
......
...@@ -8209,7 +8209,7 @@ bool JSObject::HasEnumerableElements() { ...@@ -8209,7 +8209,7 @@ bool JSObject::HasEnumerableElements() {
case DICTIONARY_ELEMENTS: { case DICTIONARY_ELEMENTS: {
SeededNumberDictionary* elements = SeededNumberDictionary* elements =
SeededNumberDictionary::cast(object->elements()); SeededNumberDictionary::cast(object->elements());
return elements->NumberOfElementsFilterAttributes(ONLY_ENUMERABLE) > 0; return elements->NumberOfEnumerableProperties() > 0;
} }
case FAST_SLOPPY_ARGUMENTS_ELEMENTS: case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
...@@ -8227,17 +8227,13 @@ bool JSObject::HasEnumerableElements() { ...@@ -8227,17 +8227,13 @@ bool JSObject::HasEnumerableElements() {
UNREACHABLE(); UNREACHABLE();
} }
int Map::NumberOfEnumerableProperties() {
int Map::NumberOfDescribedProperties(DescriptorFlag which,
PropertyFilter filter) {
int result = 0; int result = 0;
DescriptorArray* descs = instance_descriptors(); DescriptorArray* descs = instance_descriptors();
int limit = which == ALL_DESCRIPTORS int limit = NumberOfOwnDescriptors();
? descs->number_of_descriptors()
: NumberOfOwnDescriptors();
for (int i = 0; i < limit; i++) { for (int i = 0; i < limit; i++) {
if ((descs->GetDetails(i).attributes() & filter) == 0 && if ((descs->GetDetails(i).attributes() & ONLY_ENUMERABLE) == 0 &&
!descs->GetKey(i)->FilterKey(filter)) { !descs->GetKey(i)->FilterKey(ENUMERABLE_STRINGS)) {
result++; result++;
} }
} }
...@@ -16800,11 +16796,11 @@ Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >:: ...@@ -16800,11 +16796,11 @@ Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
template int NameDictionaryBase<NameDictionary, NameDictionaryShape>::FindEntry( template int NameDictionaryBase<NameDictionary, NameDictionaryShape>::FindEntry(
Handle<Name>); Handle<Name>);
template int Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: template int Dictionary<GlobalDictionary, GlobalDictionaryShape,
NumberOfElementsFilterAttributes(PropertyFilter filter); Handle<Name>>::NumberOfEnumerableProperties();
template int Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>:: template int Dictionary<NameDictionary, NameDictionaryShape,
NumberOfElementsFilterAttributes(PropertyFilter filter); Handle<Name>>::NumberOfEnumerableProperties();
template void template void
Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>:: Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::
...@@ -16850,9 +16846,8 @@ Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, ...@@ -16850,9 +16846,8 @@ Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
uint32_t key, Handle<Object> value, uint32_t key, Handle<Object> value,
PropertyDetails details, uint32_t hash); PropertyDetails details, uint32_t hash);
template int template int Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::NumberOfEnumerableProperties();
uint32_t>::NumberOfElementsFilterAttributes(PropertyFilter filter);
Handle<Object> JSObject::PrepareSlowElementsForSort( Handle<Object> JSObject::PrepareSlowElementsForSort(
Handle<JSObject> object, uint32_t limit) { Handle<JSObject> object, uint32_t limit) {
...@@ -18327,20 +18322,18 @@ Handle<UnseededNumberDictionary> UnseededNumberDictionary::Set( ...@@ -18327,20 +18322,18 @@ Handle<UnseededNumberDictionary> UnseededNumberDictionary::Set(
return dictionary; return dictionary;
} }
template <typename Derived, typename Shape, typename Key> template <typename Derived, typename Shape, typename Key>
int Dictionary<Derived, Shape, Key>::NumberOfElementsFilterAttributes( int Dictionary<Derived, Shape, Key>::NumberOfEnumerableProperties() {
PropertyFilter filter) {
Isolate* isolate = this->GetIsolate(); Isolate* isolate = this->GetIsolate();
int capacity = this->Capacity(); int capacity = this->Capacity();
int result = 0; int result = 0;
for (int i = 0; i < capacity; i++) { for (int i = 0; i < capacity; i++) {
Object* k = this->KeyAt(i); Object* k = this->KeyAt(i);
if (this->IsKey(isolate, k) && !k->FilterKey(filter)) { if (this->IsKey(isolate, k) && !k->FilterKey(ENUMERABLE_STRINGS)) {
if (this->IsDeleted(i)) continue; if (this->IsDeleted(i)) continue;
PropertyDetails details = this->DetailsAt(i); PropertyDetails details = this->DetailsAt(i);
PropertyAttributes attr = details.attributes(); PropertyAttributes attr = details.attributes();
if ((attr & filter) == 0) result++; if ((attr & ONLY_ENUMERABLE) == 0) result++;
} }
} }
return result; return result;
......
...@@ -60,14 +60,7 @@ class Dictionary : public HashTable<Derived, Shape, Key> { ...@@ -60,14 +60,7 @@ class Dictionary : public HashTable<Derived, Shape, Key> {
return DerivedHashTable::Shrink(dictionary, key); return DerivedHashTable::Shrink(dictionary, key);
} }
// Returns the number of elements in the dictionary filtering out properties int NumberOfEnumerableProperties();
// with the specified attributes.
int NumberOfElementsFilterAttributes(PropertyFilter filter);
// Returns the number of enumerable elements in the dictionary.
int NumberOfEnumElements() {
return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS);
}
enum SortMode { UNSORTED, SORTED }; enum SortMode { UNSORTED, SORTED };
......
...@@ -494,10 +494,8 @@ class Map : public HeapObject { ...@@ -494,10 +494,8 @@ class Map : public HeapObject {
// Returns the next free property index (only valid for FAST MODE). // Returns the next free property index (only valid for FAST MODE).
int NextFreePropertyIndex(); int NextFreePropertyIndex();
// Returns the number of properties described in instance_descriptors // Returns the number of enumerable properties.
// filtering out properties with the specified attributes. int NumberOfEnumerableProperties();
int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS,
PropertyFilter filter = ALL_PROPERTIES);
DECLARE_CAST(Map) DECLARE_CAST(Map)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment