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

Side by Side Diff: src/elements.cc

Issue 9174023: Split NumberDictionary into a randomly seeded and an unseeded (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 11 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 | « src/code-stubs.cc ('k') | src/factory.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 542
543 543
544 class PixelElementsAccessor 544 class PixelElementsAccessor
545 : public ExternalElementsAccessor<PixelElementsAccessor, 545 : public ExternalElementsAccessor<PixelElementsAccessor,
546 ExternalPixelArray> { 546 ExternalPixelArray> {
547 }; 547 };
548 548
549 549
550 class DictionaryElementsAccessor 550 class DictionaryElementsAccessor
551 : public ElementsAccessorBase<DictionaryElementsAccessor, 551 : public ElementsAccessorBase<DictionaryElementsAccessor,
552 NumberDictionary> { 552 SeededNumberDictionary> {
553 public: 553 public:
554 // Adjusts the length of the dictionary backing store and returns the new 554 // Adjusts the length of the dictionary backing store and returns the new
555 // length according to ES5 section 15.4.5.2 behavior. 555 // length according to ES5 section 15.4.5.2 behavior.
556 static MaybeObject* SetLengthWithoutNormalize(NumberDictionary* dict, 556 static MaybeObject* SetLengthWithoutNormalize(SeededNumberDictionary* dict,
557 JSArray* array, 557 JSArray* array,
558 Object* length_object, 558 Object* length_object,
559 uint32_t length) { 559 uint32_t length) {
560 if (length == 0) { 560 if (length == 0) {
561 // If the length of a slow array is reset to zero, we clear 561 // If the length of a slow array is reset to zero, we clear
562 // the array and flush backing storage. This has the added 562 // the array and flush backing storage. This has the added
563 // benefit that the array returns to fast mode. 563 // benefit that the array returns to fast mode.
564 Object* obj; 564 Object* obj;
565 MaybeObject* maybe_obj = array->ResetElements(); 565 MaybeObject* maybe_obj = array->ResetElements();
566 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 566 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 uint32_t key, 612 uint32_t key,
613 JSReceiver::DeleteMode mode) { 613 JSReceiver::DeleteMode mode) {
614 Isolate* isolate = obj->GetIsolate(); 614 Isolate* isolate = obj->GetIsolate();
615 Heap* heap = isolate->heap(); 615 Heap* heap = isolate->heap();
616 FixedArray* backing_store = FixedArray::cast(obj->elements()); 616 FixedArray* backing_store = FixedArray::cast(obj->elements());
617 bool is_arguments = 617 bool is_arguments =
618 (obj->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS); 618 (obj->GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS);
619 if (is_arguments) { 619 if (is_arguments) {
620 backing_store = FixedArray::cast(backing_store->get(1)); 620 backing_store = FixedArray::cast(backing_store->get(1));
621 } 621 }
622 NumberDictionary* dictionary = NumberDictionary::cast(backing_store); 622 SeededNumberDictionary* dictionary =
623 SeededNumberDictionary::cast(backing_store);
623 int entry = dictionary->FindEntry(key); 624 int entry = dictionary->FindEntry(key);
624 if (entry != NumberDictionary::kNotFound) { 625 if (entry != SeededNumberDictionary::kNotFound) {
625 Object* result = dictionary->DeleteProperty(entry, mode); 626 Object* result = dictionary->DeleteProperty(entry, mode);
626 if (result == heap->true_value()) { 627 if (result == heap->true_value()) {
627 MaybeObject* maybe_elements = dictionary->Shrink(key); 628 MaybeObject* maybe_elements = dictionary->Shrink(key);
628 FixedArray* new_elements = NULL; 629 FixedArray* new_elements = NULL;
629 if (!maybe_elements->To(&new_elements)) { 630 if (!maybe_elements->To(&new_elements)) {
630 return maybe_elements; 631 return maybe_elements;
631 } 632 }
632 if (is_arguments) { 633 if (is_arguments) {
633 FixedArray::cast(obj->elements())->set(1, new_elements); 634 FixedArray::cast(obj->elements())->set(1, new_elements);
634 } else { 635 } else {
(...skipping 12 matching lines...) Expand all
647 isolate->factory()->NewTypeError("strict_delete_property", 648 isolate->factory()->NewTypeError("strict_delete_property",
648 HandleVector(args, 2)); 649 HandleVector(args, 2));
649 return isolate->Throw(*error); 650 return isolate->Throw(*error);
650 } 651 }
651 } 652 }
652 return heap->true_value(); 653 return heap->true_value();
653 } 654 }
654 655
655 protected: 656 protected:
656 friend class ElementsAccessorBase<DictionaryElementsAccessor, 657 friend class ElementsAccessorBase<DictionaryElementsAccessor,
657 NumberDictionary>; 658 SeededNumberDictionary>;
658 659
659 virtual MaybeObject* Delete(JSObject* obj, 660 virtual MaybeObject* Delete(JSObject* obj,
660 uint32_t key, 661 uint32_t key,
661 JSReceiver::DeleteMode mode) { 662 JSReceiver::DeleteMode mode) {
662 return DeleteCommon(obj, key, mode); 663 return DeleteCommon(obj, key, mode);
663 } 664 }
664 665
665 static MaybeObject* Get(NumberDictionary* backing_store, 666 static MaybeObject* Get(SeededNumberDictionary* backing_store,
666 uint32_t key, 667 uint32_t key,
667 JSObject* obj, 668 JSObject* obj,
668 Object* receiver) { 669 Object* receiver) {
669 int entry = backing_store->FindEntry(key); 670 int entry = backing_store->FindEntry(key);
670 if (entry != NumberDictionary::kNotFound) { 671 if (entry != SeededNumberDictionary::kNotFound) {
671 Object* element = backing_store->ValueAt(entry); 672 Object* element = backing_store->ValueAt(entry);
672 PropertyDetails details = backing_store->DetailsAt(entry); 673 PropertyDetails details = backing_store->DetailsAt(entry);
673 if (details.type() == CALLBACKS) { 674 if (details.type() == CALLBACKS) {
674 return obj->GetElementWithCallback(receiver, 675 return obj->GetElementWithCallback(receiver,
675 element, 676 element,
676 key, 677 key,
677 obj); 678 obj);
678 } else { 679 } else {
679 return element; 680 return element;
680 } 681 }
681 } 682 }
682 return obj->GetHeap()->the_hole_value(); 683 return obj->GetHeap()->the_hole_value();
683 } 684 }
684 685
685 static uint32_t GetKeyForIndex(NumberDictionary* dict, 686 static uint32_t GetKeyForIndex(SeededNumberDictionary* dict,
686 uint32_t index) { 687 uint32_t index) {
687 Object* key = dict->KeyAt(index); 688 Object* key = dict->KeyAt(index);
688 return Smi::cast(key)->value(); 689 return Smi::cast(key)->value();
689 } 690 }
690 }; 691 };
691 692
692 693
693 class NonStrictArgumentsElementsAccessor 694 class NonStrictArgumentsElementsAccessor
694 : public ElementsAccessorBase<NonStrictArgumentsElementsAccessor, 695 : public ElementsAccessorBase<NonStrictArgumentsElementsAccessor,
695 FixedArray> { 696 FixedArray> {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } else { 889 } else {
889 return ThrowArrayLengthRangeError(array->GetHeap()); 890 return ThrowArrayLengthRangeError(array->GetHeap());
890 } 891 }
891 } 892 }
892 893
893 // Slow case: The new length does not fit into a Smi or conversion 894 // Slow case: The new length does not fit into a Smi or conversion
894 // to slow elements is needed for other reasons. 895 // to slow elements is needed for other reasons.
895 if (length->IsNumber()) { 896 if (length->IsNumber()) {
896 uint32_t value; 897 uint32_t value;
897 if (length->ToArrayIndex(&value)) { 898 if (length->ToArrayIndex(&value)) {
898 NumberDictionary* dictionary; 899 SeededNumberDictionary* dictionary;
899 MaybeObject* maybe_object = array->NormalizeElements(); 900 MaybeObject* maybe_object = array->NormalizeElements();
900 if (!maybe_object->To(&dictionary)) return maybe_object; 901 if (!maybe_object->To(&dictionary)) return maybe_object;
901 Object* new_length; 902 Object* new_length;
902 MaybeObject* result = DictionaryElementsAccessor:: 903 MaybeObject* result = DictionaryElementsAccessor::
903 SetLengthWithoutNormalize(dictionary, array, length, value); 904 SetLengthWithoutNormalize(dictionary, array, length, value);
904 if (!result->ToObject(&new_length)) return result; 905 if (!result->ToObject(&new_length)) return result;
905 ASSERT(new_length->IsNumber()); 906 ASSERT(new_length->IsNumber());
906 array->set_length(new_length); 907 array->set_length(new_length);
907 return array; 908 return array;
908 } else { 909 } else {
909 return ThrowArrayLengthRangeError(array->GetHeap()); 910 return ThrowArrayLengthRangeError(array->GetHeap());
910 } 911 }
911 } 912 }
912 913
913 // Fall-back case: The new length is not a number so make the array 914 // Fall-back case: The new length is not a number so make the array
914 // size one and set only element to length. 915 // size one and set only element to length.
915 FixedArray* new_backing_store; 916 FixedArray* new_backing_store;
916 MaybeObject* maybe_obj = array->GetHeap()->AllocateFixedArray(1); 917 MaybeObject* maybe_obj = array->GetHeap()->AllocateFixedArray(1);
917 if (!maybe_obj->To(&new_backing_store)) return maybe_obj; 918 if (!maybe_obj->To(&new_backing_store)) return maybe_obj;
918 new_backing_store->set(0, length); 919 new_backing_store->set(0, length);
919 array->SetContent(new_backing_store); 920 array->SetContent(new_backing_store);
920 return array; 921 return array;
921 } 922 }
922 923
923 924
924 } } // namespace v8::internal 925 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/code-stubs.cc ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698