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

Side by Side Diff: src/builtins.cc

Issue 1958713003: Various species micro-optimizations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug and formatting Created 4 years, 7 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/isolate.h » ('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-arguments.h" 7 #include "src/api-arguments.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 BUILTIN(ArraySlice) { 551 BUILTIN(ArraySlice) {
552 HandleScope scope(isolate); 552 HandleScope scope(isolate);
553 Handle<Object> receiver = args.receiver(); 553 Handle<Object> receiver = args.receiver();
554 int len = -1; 554 int len = -1;
555 int relative_start = 0; 555 int relative_start = 0;
556 int relative_end = 0; 556 int relative_end = 0;
557 557
558 if (receiver->IsJSArray()) { 558 if (receiver->IsJSArray()) {
559 DisallowHeapAllocation no_gc; 559 DisallowHeapAllocation no_gc;
560 JSArray* array = JSArray::cast(*receiver); 560 JSArray* array = JSArray::cast(*receiver);
561 if (!array->HasFastElements() || 561 if (V8_UNLIKELY(!array->HasFastElements() ||
562 !IsJSArrayFastElementMovingAllowed(isolate, array) || 562 !IsJSArrayFastElementMovingAllowed(isolate, array) ||
563 !isolate->IsArraySpeciesLookupChainIntact() || 563 !isolate->IsArraySpeciesLookupChainIntact() ||
564 // If this is a subclass of Array, then call out to JS 564 // If this is a subclass of Array, then call out to JS
565 !array->HasArrayPrototype(isolate)) { 565 !array->HasArrayPrototype(isolate))) {
566 AllowHeapAllocation allow_allocation; 566 AllowHeapAllocation allow_allocation;
567 return CallJsIntrinsic(isolate, isolate->array_slice(), args); 567 return CallJsIntrinsic(isolate, isolate->array_slice(), args);
568 } 568 }
569 len = Smi::cast(array->length())->value(); 569 len = Smi::cast(array->length())->value();
570 } else if (receiver->IsJSObject() && 570 } else if (receiver->IsJSObject() &&
571 GetSloppyArgumentsLength(isolate, Handle<JSObject>::cast(receiver), 571 GetSloppyArgumentsLength(isolate, Handle<JSObject>::cast(receiver),
572 &len)) { 572 &len)) {
573 // Array.prototype.slice.call(arguments, ...) is quite a common idiom 573 // Array.prototype.slice.call(arguments, ...) is quite a common idiom
574 // (notably more than 50% of invocations in Web apps). 574 // (notably more than 50% of invocations in Web apps).
575 // Treat it in C++ as well. 575 // Treat it in C++ as well.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 614
615 Handle<JSObject> object = Handle<JSObject>::cast(receiver); 615 Handle<JSObject> object = Handle<JSObject>::cast(receiver);
616 ElementsAccessor* accessor = object->GetElementsAccessor(); 616 ElementsAccessor* accessor = object->GetElementsAccessor();
617 return *accessor->Slice(object, actual_start, actual_end); 617 return *accessor->Slice(object, actual_start, actual_end);
618 } 618 }
619 619
620 620
621 BUILTIN(ArraySplice) { 621 BUILTIN(ArraySplice) {
622 HandleScope scope(isolate); 622 HandleScope scope(isolate);
623 Handle<Object> receiver = args.receiver(); 623 Handle<Object> receiver = args.receiver();
624 if (!EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3) || 624 if (V8_UNLIKELY(
625 // If this is a subclass of Array, then call out to JS. 625 !EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3) ||
626 !Handle<JSArray>::cast(receiver)->HasArrayPrototype(isolate) || 626 // If this is a subclass of Array, then call out to JS.
627 // If anything with @@species has been messed with, call out to JS. 627 !Handle<JSArray>::cast(receiver)->HasArrayPrototype(isolate) ||
628 !isolate->IsArraySpeciesLookupChainIntact()) { 628 // If anything with @@species has been messed with, call out to JS.
629 !isolate->IsArraySpeciesLookupChainIntact())) {
629 return CallJsIntrinsic(isolate, isolate->array_splice(), args); 630 return CallJsIntrinsic(isolate, isolate->array_splice(), args);
630 } 631 }
631 Handle<JSArray> array = Handle<JSArray>::cast(receiver); 632 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
632 633
633 int argument_count = args.length() - 1; 634 int argument_count = args.length() - 1;
634 int relative_start = 0; 635 int relative_start = 0;
635 if (argument_count > 0) { 636 if (argument_count > 0) {
636 DisallowHeapAllocation no_gc; 637 DisallowHeapAllocation no_gc;
637 if (!ClampedToInteger(args[1], &relative_start)) { 638 if (!ClampedToInteger(args[1], &relative_start)) {
638 AllowHeapAllocation allow_allocation; 639 AllowHeapAllocation allow_allocation;
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, 1485 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
1485 isolate->factory()->NewStringFromAsciiChecked( 1486 isolate->factory()->NewStringFromAsciiChecked(
1486 "Array.prototype.concat"))); 1487 "Array.prototype.concat")));
1487 } 1488 }
1488 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1489 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1489 isolate, receiver, Object::ToObject(isolate, args.receiver())); 1490 isolate, receiver, Object::ToObject(isolate, args.receiver()));
1490 args[0] = *receiver; 1491 args[0] = *receiver;
1491 1492
1492 Handle<JSArray> result_array; 1493 Handle<JSArray> result_array;
1493 1494
1495 // Avoid a real species read to avoid extra lookups to the array constructor
1496 if (V8_LIKELY(receiver->IsJSArray() &&
1497 Handle<JSArray>::cast(receiver)->HasArrayPrototype(isolate) &&
1498 isolate->IsArraySpeciesLookupChainIntact())) {
1499 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) {
1500 return *result_array;
1501 }
1502 if (isolate->has_pending_exception()) return isolate->heap()->exception();
1503 }
1494 // Reading @@species happens before anything else with a side effect, so 1504 // Reading @@species happens before anything else with a side effect, so
1495 // we can do it here to determine whether to take the fast path. 1505 // we can do it here to determine whether to take the fast path.
1496 Handle<Object> species; 1506 Handle<Object> species;
1497 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1507 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1498 isolate, species, Object::ArraySpeciesConstructor(isolate, receiver)); 1508 isolate, species, Object::ArraySpeciesConstructor(isolate, receiver));
1499 if (*species == isolate->context()->native_context()->array_function()) { 1509 if (*species == *isolate->array_function()) {
1500 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) { 1510 if (Fast_ArrayConcat(isolate, &args).ToHandle(&result_array)) {
1501 return *result_array; 1511 return *result_array;
1502 } 1512 }
1503 if (isolate->has_pending_exception()) return isolate->heap()->exception(); 1513 if (isolate->has_pending_exception()) return isolate->heap()->exception();
1504 } 1514 }
1505 return Slow_ArrayConcat(&args, species, isolate); 1515 return Slow_ArrayConcat(&args, species, isolate);
1506 } 1516 }
1507 1517
1508 1518
1509 namespace { 1519 namespace {
(...skipping 3946 matching lines...) Expand 10 before | Expand all | Expand 10 after
5456 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5466 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
5457 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5467 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
5458 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5468 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
5459 #undef DEFINE_BUILTIN_ACCESSOR_C 5469 #undef DEFINE_BUILTIN_ACCESSOR_C
5460 #undef DEFINE_BUILTIN_ACCESSOR_A 5470 #undef DEFINE_BUILTIN_ACCESSOR_A
5461 #undef DEFINE_BUILTIN_ACCESSOR_T 5471 #undef DEFINE_BUILTIN_ACCESSOR_T
5462 #undef DEFINE_BUILTIN_ACCESSOR_H 5472 #undef DEFINE_BUILTIN_ACCESSOR_H
5463 5473
5464 } // namespace internal 5474 } // namespace internal
5465 } // namespace v8 5475 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698