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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 } 1759 }
1760 1760
1761 1761
1762 // ES6 section 19.1.2.14 Object.keys ( O ) 1762 // ES6 section 19.1.2.14 Object.keys ( O )
1763 BUILTIN(ObjectKeys) { 1763 BUILTIN(ObjectKeys) {
1764 HandleScope scope(isolate); 1764 HandleScope scope(isolate);
1765 Handle<Object> object = args.atOrUndefined(isolate, 1); 1765 Handle<Object> object = args.atOrUndefined(isolate, 1);
1766 Handle<JSReceiver> receiver; 1766 Handle<JSReceiver> receiver;
1767 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 1767 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1768 Object::ToObject(isolate, object)); 1768 Object::ToObject(isolate, object));
1769
1769 Handle<FixedArray> keys; 1770 Handle<FixedArray> keys;
1770 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1771 int enum_length = receiver->map()->EnumLength();
1771 isolate, keys, JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS, 1772 if (enum_length != kInvalidEnumCacheSentinel) {
1772 CONVERT_TO_STRING)); 1773 DCHECK(receiver->IsJSObject());
1773 return *isolate->factory()->NewJSArrayWithElements(keys); 1774 Handle<JSObject> js_object = Handle<JSObject>::cast(receiver);
1775 DCHECK(!js_object->HasNamedInterceptor());
1776 DCHECK(!js_object->IsAccessCheckNeeded());
1777 DCHECK(!js_object->map()->has_hidden_prototype());
1778 DCHECK(js_object->HasFastProperties());
1779 if (js_object->elements() == isolate->heap()->empty_fixed_array()) {
1780 keys = isolate->factory()->NewFixedArray(enum_length);
1781 if (enum_length != 0) {
1782 Handle<FixedArray> cache(
1783 js_object->map()->instance_descriptors()->GetEnumCache());
1784 keys = isolate->factory()->NewFixedArray(enum_length);
1785 for (int i = 0; i < enum_length; i++) {
1786 keys->set(i, cache->get(i));
1787 }
1788 }
1789 }
1790 }
1791
1792 if (keys.is_null()) {
1793 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1794 isolate, keys,
1795 JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS,
1796 CONVERT_TO_STRING));
1797 }
1798 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS);
1774 } 1799 }
1775 1800
1776
1777 BUILTIN(ObjectValues) { 1801 BUILTIN(ObjectValues) {
1778 HandleScope scope(isolate); 1802 HandleScope scope(isolate);
1779 Handle<Object> object = args.atOrUndefined(isolate, 1); 1803 Handle<Object> object = args.atOrUndefined(isolate, 1);
1780 Handle<JSReceiver> receiver; 1804 Handle<JSReceiver> receiver;
1781 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 1805 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1782 Object::ToObject(isolate, object)); 1806 Object::ToObject(isolate, object));
1783 Handle<FixedArray> values; 1807 Handle<FixedArray> values;
1784 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1808 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1785 isolate, values, JSReceiver::GetOwnValues(receiver, ENUMERABLE_STRINGS)); 1809 isolate, values, JSReceiver::GetOwnValues(receiver, ENUMERABLE_STRINGS));
1786 return *isolate->factory()->NewJSArrayWithElements(values); 1810 return *isolate->factory()->NewJSArrayWithElements(values);
(...skipping 2449 matching lines...) Expand 10 before | Expand all | Expand 10 after
4236 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4260 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
4237 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4261 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
4238 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4262 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4239 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4263 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4240 #undef DEFINE_BUILTIN_ACCESSOR_C 4264 #undef DEFINE_BUILTIN_ACCESSOR_C
4241 #undef DEFINE_BUILTIN_ACCESSOR_A 4265 #undef DEFINE_BUILTIN_ACCESSOR_A
4242 4266
4243 4267
4244 } // namespace internal 4268 } // namespace internal
4245 } // namespace v8 4269 } // namespace v8
OLDNEW
« 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