Commit 8e5840e1 authored by neis's avatar neis Committed by Commit bot

Sort names in JSObject::CollectOwnPropertyNames.

R=cbruni, rossberg
BUG=

Review URL: https://codereview.chromium.org/1453583002

Cr-Commit-Position: refs/heads/master@{#32063}
parent 74145470
......@@ -52,6 +52,7 @@ class KeyAccumulator final BASE_EMBEDDED {
void SortCurrentElementsList();
Handle<FixedArray> GetKeys(GetKeysConversion convert = KEEP_NUMBERS);
int length() { return length_; }
Isolate* isolate() { return isolate_; }
private:
bool AddIntegerKey(uint32_t key);
......
......@@ -15097,10 +15097,9 @@ int JSObject::GetOwnPropertyNames(FixedArray* storage, int index,
}
int JSObject::CollectOwnPropertyNames(KeyAccumulator* keys,
PropertyAttributes filter) {
void JSObject::CollectOwnPropertyNames(KeyAccumulator* keys,
PropertyAttributes filter) {
if (HasFastProperties()) {
int nof_keys = keys->length();
int real_size = map()->NumberOfOwnDescriptors();
Handle<DescriptorArray> descs(map()->instance_descriptors());
for (int i = 0; i < real_size; i++) {
......@@ -15109,11 +15108,10 @@ int JSObject::CollectOwnPropertyNames(KeyAccumulator* keys,
if (key->FilterKey(filter)) continue;
keys->AddKey(key);
}
return nof_keys - keys->length();
} else if (IsJSGlobalObject()) {
return global_dictionary()->CollectKeysTo(keys, filter);
global_dictionary()->CollectKeysTo(keys, filter);
} else {
return property_dictionary()->CollectKeysTo(keys, filter);
property_dictionary()->CollectKeysTo(keys, filter);
}
}
......@@ -16904,10 +16902,13 @@ int Dictionary<Derived, Shape, Key>::CopyKeysTo(
template <typename Derived, typename Shape, typename Key>
int Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys,
PropertyAttributes filter) {
void Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys,
PropertyAttributes filter) {
int capacity = this->Capacity();
int keyLength = keys->length();
Handle<FixedArray> array =
keys->isolate()->factory()->NewFixedArray(this->NumberOfElements());
int array_size = 0;
for (int i = 0; i < capacity; i++) {
Object* k = this->KeyAt(i);
if (!this->IsKey(k) || k->FilterKey(filter)) continue;
......@@ -16915,9 +16916,16 @@ int Dictionary<Derived, Shape, Key>::CollectKeysTo(KeyAccumulator* keys,
PropertyDetails details = this->DetailsAt(i);
PropertyAttributes attr = details.attributes();
if ((attr & filter) != 0) continue;
keys->AddKey(k);
array->set(array_size++, Smi::FromInt(i));
}
EnumIndexComparator<Derived> cmp(static_cast<Derived*>(this));
Smi** start = reinterpret_cast<Smi**>(array->GetFirstElementAddress());
std::sort(start, start + array_size, cmp);
for (int i = 0; i < array_size; i++) {
int index = Smi::cast(array->get(i))->value();
keys->AddKey(this->KeyAt(index));
}
return keyLength - keys->length();
}
......
......@@ -2257,8 +2257,8 @@ class JSObject: public JSReceiver {
// index. Returns the number of properties added.
int GetOwnPropertyNames(FixedArray* storage, int index,
PropertyAttributes filter = NONE);
int CollectOwnPropertyNames(KeyAccumulator* keys,
PropertyAttributes filter = NONE);
void CollectOwnPropertyNames(KeyAccumulator* keys,
PropertyAttributes filter = NONE);
// Returns the number of properties on this object filtering out properties
// with the specified attributes (ignoring interceptors).
......@@ -3400,8 +3400,9 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Returns the number of properties added.
int CopyKeysTo(FixedArray* storage, int index, PropertyAttributes filter,
SortMode sort_mode);
// Collect the unsorted keys into the given KeyAccumulator.
int CollectKeysTo(KeyAccumulator* keys, PropertyAttributes filter);
// Collect the keys into the given KeyAccumulator, in ascending chronological
// order of property creation.
void CollectKeysTo(KeyAccumulator* keys, PropertyAttributes filter);
// Copies enumerable keys to preallocated fixed array.
void CopyEnumKeysTo(FixedArray* storage);
......
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