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

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: 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 fefdc5be48dde724d2eeff54368985392a6dc7b3..56699e9fad4b781d026faf88c6a8c8f326b95031 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -15096,10 +15096,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++) {
@@ -15108,11 +15107,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);
}
}
@@ -16903,10 +16901,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(capacity);
Camillo Bruni 2015/11/17 10:02:52 I think NumberOfElements() would be better here no
+ int array_size = 0;
+
for (int i = 0; i < capacity; i++) {
Object* k = this->KeyAt(i);
if (!this->IsKey(k) || k->FilterKey(filter)) continue;
@@ -16914,9 +16915,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