Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Unified Diff: src/objects.cc

Issue 1453583002: Sort names in JSObject::CollectOwnPropertyNames. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 6123008afacbb9cd32133dcbfbd6fadd8a20503c..6c1b78acbfc7e03c7b51346bae60ebe85e6949a2 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -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();
}
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698