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,
DescriptorArray* descriptors) {
int live_enum = map->EnumLength();
if (live_enum == kInvalidEnumCacheSentinel) {
live_enum =
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS);
live_enum = map->NumberOfEnumerableProperties();
}
if (live_enum == 0) return descriptors->ClearEnumCache();
......
......@@ -218,11 +218,7 @@ void TrySettingEmptyEnumCache(JSReceiver* object) {
DCHECK_EQ(kInvalidEnumCacheSentinel, map->EnumLength());
if (!map->OnlyHasSimpleProperties()) return;
if (map->IsJSProxyMap()) return;
if (map->NumberOfOwnDescriptors() > 0) {
int number_of_enumerable_own_properties =
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS);
if (number_of_enumerable_own_properties > 0) return;
}
if (map->NumberOfEnumerableProperties() > 0) return;
DCHECK(object->IsJSObject());
map->SetEnumLength(0);
}
......@@ -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
// counting the number of own descriptors that are ENUMERABLE_STRINGS.
if (own_property_count == kInvalidEnumCacheSentinel) {
own_property_count =
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS);
own_property_count = map->NumberOfEnumerableProperties();
} else {
DCHECK(
own_property_count ==
map->NumberOfDescribedProperties(OWN_DESCRIPTORS, ENUMERABLE_STRINGS));
DCHECK_EQ(own_property_count, map->NumberOfEnumerableProperties());
}
if (descs->HasEnumCache()) {
......@@ -574,7 +567,7 @@ Handle<FixedArray> GetOwnEnumPropertyDictionaryKeys(Isolate* isolate,
Handle<JSObject> object,
T* raw_dictionary) {
Handle<T> dictionary(raw_dictionary, isolate);
int length = dictionary->NumberOfEnumElements();
int length = dictionary->NumberOfEnumerableProperties();
if (length == 0) {
return isolate->factory()->empty_fixed_array();
}
......
......@@ -8209,7 +8209,7 @@ bool JSObject::HasEnumerableElements() {
case DICTIONARY_ELEMENTS: {
SeededNumberDictionary* elements =
SeededNumberDictionary::cast(object->elements());
return elements->NumberOfElementsFilterAttributes(ONLY_ENUMERABLE) > 0;
return elements->NumberOfEnumerableProperties() > 0;
}
case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
case SLOW_SLOPPY_ARGUMENTS_ELEMENTS:
......@@ -8227,17 +8227,13 @@ bool JSObject::HasEnumerableElements() {
UNREACHABLE();
}
int Map::NumberOfDescribedProperties(DescriptorFlag which,
PropertyFilter filter) {
int Map::NumberOfEnumerableProperties() {
int result = 0;
DescriptorArray* descs = instance_descriptors();
int limit = which == ALL_DESCRIPTORS
? descs->number_of_descriptors()
: NumberOfOwnDescriptors();
int limit = NumberOfOwnDescriptors();
for (int i = 0; i < limit; i++) {
if ((descs->GetDetails(i).attributes() & filter) == 0 &&
!descs->GetKey(i)->FilterKey(filter)) {
if ((descs->GetDetails(i).attributes() & ONLY_ENUMERABLE) == 0 &&
!descs->GetKey(i)->FilterKey(ENUMERABLE_STRINGS)) {
result++;
}
}
......@@ -16800,11 +16796,11 @@ Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
template int NameDictionaryBase<NameDictionary, NameDictionaryShape>::FindEntry(
Handle<Name>);
template int Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::
NumberOfElementsFilterAttributes(PropertyFilter filter);
template int Dictionary<GlobalDictionary, GlobalDictionaryShape,
Handle<Name>>::NumberOfEnumerableProperties();
template int Dictionary<NameDictionary, NameDictionaryShape, Handle<Name>>::
NumberOfElementsFilterAttributes(PropertyFilter filter);
template int Dictionary<NameDictionary, NameDictionaryShape,
Handle<Name>>::NumberOfEnumerableProperties();
template void
Dictionary<GlobalDictionary, GlobalDictionaryShape, Handle<Name>>::
......@@ -16850,9 +16846,8 @@ Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
uint32_t key, Handle<Object> value,
PropertyDetails details, uint32_t hash);
template int
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
uint32_t>::NumberOfElementsFilterAttributes(PropertyFilter filter);
template int Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape,
uint32_t>::NumberOfEnumerableProperties();
Handle<Object> JSObject::PrepareSlowElementsForSort(
Handle<JSObject> object, uint32_t limit) {
......@@ -18327,20 +18322,18 @@ Handle<UnseededNumberDictionary> UnseededNumberDictionary::Set(
return dictionary;
}
template <typename Derived, typename Shape, typename Key>
int Dictionary<Derived, Shape, Key>::NumberOfElementsFilterAttributes(
PropertyFilter filter) {
int Dictionary<Derived, Shape, Key>::NumberOfEnumerableProperties() {
Isolate* isolate = this->GetIsolate();
int capacity = this->Capacity();
int result = 0;
for (int i = 0; i < capacity; 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;
PropertyDetails details = this->DetailsAt(i);
PropertyAttributes attr = details.attributes();
if ((attr & filter) == 0) result++;
if ((attr & ONLY_ENUMERABLE) == 0) result++;
}
}
return result;
......
......@@ -60,14 +60,7 @@ class Dictionary : public HashTable<Derived, Shape, Key> {
return DerivedHashTable::Shrink(dictionary, key);
}
// Returns the number of elements in the dictionary filtering out properties
// with the specified attributes.
int NumberOfElementsFilterAttributes(PropertyFilter filter);
// Returns the number of enumerable elements in the dictionary.
int NumberOfEnumElements() {
return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS);
}
int NumberOfEnumerableProperties();
enum SortMode { UNSORTED, SORTED };
......
......@@ -494,10 +494,8 @@ class Map : public HeapObject {
// Returns the next free property index (only valid for FAST MODE).
int NextFreePropertyIndex();
// Returns the number of properties described in instance_descriptors
// filtering out properties with the specified attributes.
int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS,
PropertyFilter filter = ALL_PROPERTIES);
// Returns the number of enumerable properties.
int NumberOfEnumerableProperties();
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