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

Side by Side Diff: src/builtins.cc

Issue 247613002: Micro-optimizations to pop() and shift() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Returns empty handle if not applicable. 295 // Returns empty handle if not applicable.
296 MUST_USE_RESULT 296 MUST_USE_RESULT
297 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements( 297 static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
298 Isolate* isolate, 298 Isolate* isolate,
299 Handle<Object> receiver, 299 Handle<Object> receiver,
300 Arguments* args, 300 Arguments* args,
301 int first_added_arg) { 301 int first_added_arg) {
302 if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>(); 302 if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>();
303 Handle<JSArray> array = Handle<JSArray>::cast(receiver); 303 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
304 // If there may be elements accessors in the prototype chain, the fast path 304 // If there may be elements accessors in the prototype chain, the fast path
305 // cannot be used. 305 // cannot be used if there arguments to add to the array.
306 if (array->map()->DictionaryElementsInPrototypeChainOnly()) { 306 if (args != NULL && array->map()->DictionaryElementsInPrototypeChainOnly()) {
307 return MaybeHandle<FixedArrayBase>(); 307 return MaybeHandle<FixedArrayBase>();
308 } 308 }
309 if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>(); 309 if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>();
310 if (!array->map()->is_extensible()) return MaybeHandle<FixedArrayBase>(); 310 if (!array->map()->is_extensible()) return MaybeHandle<FixedArrayBase>();
311 Handle<FixedArrayBase> elms(array->elements(), isolate); 311 Handle<FixedArrayBase> elms(array->elements(), isolate);
312 Heap* heap = isolate->heap(); 312 Heap* heap = isolate->heap();
313 Map* map = elms->map(); 313 Map* map = elms->map();
314 if (map == heap->fixed_array_map()) { 314 if (map == heap->fixed_array_map()) {
315 if (args == NULL || array->HasFastObjectElements()) return elms; 315 if (args == NULL || array->HasFastObjectElements()) return elms;
316 } else if (map == heap->fixed_cow_array_map()) { 316 } else if (map == heap->fixed_cow_array_map()) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 513 }
514 514
515 Handle<JSArray> array = Handle<JSArray>::cast(receiver); 515 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
516 ASSERT(!array->map()->is_observed()); 516 ASSERT(!array->map()->is_observed());
517 517
518 int len = Smi::cast(array->length())->value(); 518 int len = Smi::cast(array->length())->value();
519 if (len == 0) return isolate->heap()->undefined_value(); 519 if (len == 0) return isolate->heap()->undefined_value();
520 520
521 ElementsAccessor* accessor = array->GetElementsAccessor(); 521 ElementsAccessor* accessor = array->GetElementsAccessor();
522 int new_length = len - 1; 522 int new_length = len - 1;
523 MaybeHandle<Object> maybe_element; 523 Handle<Object> element =
524 if (accessor->HasElement(array, array, new_length, elms_obj)) { 524 accessor->Get(array, array, new_length, elms_obj).ToHandleChecked();
525 maybe_element = accessor->Get(array, array, new_length, elms_obj); 525 if (element->IsTheHole()) {
526 } else { 526 return CallJsBuiltin(isolate, "ArrayPop", args);
527 Handle<Object> proto(array->GetPrototype(), isolate);
528 maybe_element = Object::GetElement(isolate, proto, len - 1);
529 } 527 }
530 Handle<Object> element;
531 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, element, maybe_element);
532 RETURN_IF_EMPTY_HANDLE( 528 RETURN_IF_EMPTY_HANDLE(
533 isolate, 529 isolate,
534 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate))); 530 accessor->SetLength(array, handle(Smi::FromInt(new_length), isolate)));
535 return *element; 531 return *element;
536 } 532 }
537 533
538 534
539 BUILTIN(ArrayShift) { 535 BUILTIN(ArrayShift) {
540 HandleScope scope(isolate); 536 HandleScope scope(isolate);
541 Heap* heap = isolate->heap(); 537 Heap* heap = isolate->heap();
542 Handle<Object> receiver = args.receiver(); 538 Handle<Object> receiver = args.receiver();
543 MaybeHandle<FixedArrayBase> maybe_elms_obj = 539 MaybeHandle<FixedArrayBase> maybe_elms_obj =
544 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0); 540 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0);
545 Handle<FixedArrayBase> elms_obj; 541 Handle<FixedArrayBase> elms_obj;
546 if (!maybe_elms_obj.ToHandle(&elms_obj) || 542 if (!maybe_elms_obj.ToHandle(&elms_obj) ||
547 !IsJSArrayFastElementMovingAllowed(heap, 543 !IsJSArrayFastElementMovingAllowed(heap,
548 *Handle<JSArray>::cast(receiver))) { 544 *Handle<JSArray>::cast(receiver))) {
549 return CallJsBuiltin(isolate, "ArrayShift", args); 545 return CallJsBuiltin(isolate, "ArrayShift", args);
550 } 546 }
551 Handle<JSArray> array = Handle<JSArray>::cast(receiver); 547 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
552 ASSERT(!array->map()->is_observed()); 548 ASSERT(!array->map()->is_observed());
553 549
554 int len = Smi::cast(array->length())->value(); 550 int len = Smi::cast(array->length())->value();
555 if (len == 0) return heap->undefined_value(); 551 if (len == 0) return heap->undefined_value();
556 552
557 // Get first element 553 // Get first element
558 ElementsAccessor* accessor = array->GetElementsAccessor(); 554 ElementsAccessor* accessor = array->GetElementsAccessor();
559 Handle<Object> first; 555 Handle<Object> first =
560 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 556 accessor->Get(array, array, 0, elms_obj).ToHandleChecked();
561 isolate, first, accessor->Get(receiver, array, 0, elms_obj));
562 if (first->IsTheHole()) { 557 if (first->IsTheHole()) {
563 first = isolate->factory()->undefined_value(); 558 return CallJsBuiltin(isolate, "ArrayShift", args);
564 } 559 }
565 560
566 if (heap->CanMoveObjectStart(*elms_obj)) { 561 if (heap->CanMoveObjectStart(*elms_obj)) {
567 array->set_elements(LeftTrimFixedArray(heap, *elms_obj, 1)); 562 array->set_elements(LeftTrimFixedArray(heap, *elms_obj, 1));
568 } else { 563 } else {
569 // Shift the elements. 564 // Shift the elements.
570 if (elms_obj->IsFixedArray()) { 565 if (elms_obj->IsFixedArray()) {
571 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj); 566 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
572 DisallowHeapAllocation no_gc; 567 DisallowHeapAllocation no_gc;
573 heap->MoveElements(*elms, 0, 1, len - 1); 568 heap->MoveElements(*elms, 0, 1, len - 1);
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 } 1729 }
1735 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1730 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1736 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1731 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1737 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 1732 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
1738 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1733 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1739 #undef DEFINE_BUILTIN_ACCESSOR_C 1734 #undef DEFINE_BUILTIN_ACCESSOR_C
1740 #undef DEFINE_BUILTIN_ACCESSOR_A 1735 #undef DEFINE_BUILTIN_ACCESSOR_A
1741 1736
1742 1737
1743 } } // namespace v8::internal 1738 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698