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

Unified Diff: src/builtins.cc

Issue 1682873003: [builtins] Speedup Object.keys by adding a fast path for objects without elements, interceptors, ... (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months 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 | « no previous file | src/objects.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index 806f8d6bd6bf8031b0ca22ae248432a9e1290577..7cc65cdabbb7c9433c3a9612d109d6349b2c1f00 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1766,13 +1766,37 @@ BUILTIN(ObjectKeys) {
Handle<JSReceiver> receiver;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
Object::ToObject(isolate, object));
+
Handle<FixedArray> keys;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
- isolate, keys, JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS,
- CONVERT_TO_STRING));
- return *isolate->factory()->NewJSArrayWithElements(keys);
-}
+ int enum_length = receiver->map()->EnumLength();
+ if (enum_length != kInvalidEnumCacheSentinel) {
+ DCHECK(receiver->IsJSObject());
+ Handle<JSObject> js_object = Handle<JSObject>::cast(receiver);
+ DCHECK(!js_object->HasNamedInterceptor());
+ DCHECK(!js_object->IsAccessCheckNeeded());
+ DCHECK(!js_object->map()->has_hidden_prototype());
+ DCHECK(js_object->HasFastProperties());
+ if (js_object->elements() == isolate->heap()->empty_fixed_array()) {
+ keys = isolate->factory()->NewFixedArray(enum_length);
+ if (enum_length != 0) {
+ Handle<FixedArray> cache(
+ js_object->map()->instance_descriptors()->GetEnumCache());
+ keys = isolate->factory()->NewFixedArray(enum_length);
+ for (int i = 0; i < enum_length; i++) {
+ keys->set(i, cache->get(i));
+ }
+ }
+ }
+ }
+ if (keys.is_null()) {
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, keys,
+ JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS,
+ CONVERT_TO_STRING));
+ }
+ return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS);
+}
BUILTIN(ObjectValues) {
HandleScope scope(isolate);
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698