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

Side by Side Diff: src/elements.cc

Issue 1194943004: Get rid of JSArray::Expand and friends (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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 | « src/elements.h ('k') | src/json-stringifier.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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/elements.h" 9 #include "src/elements.h"
10 #include "src/messages.h" 10 #include "src/messages.h"
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } 637 }
638 638
639 virtual void SetLength(Handle<JSArray> array, uint32_t length) final { 639 virtual void SetLength(Handle<JSArray> array, uint32_t length) final {
640 ElementsAccessorSubclass::SetLengthImpl(array, length, 640 ElementsAccessorSubclass::SetLengthImpl(array, length,
641 handle(array->elements())); 641 handle(array->elements()));
642 } 642 }
643 643
644 static void SetLengthImpl(Handle<JSArray> array, uint32_t length, 644 static void SetLengthImpl(Handle<JSArray> array, uint32_t length,
645 Handle<FixedArrayBase> backing_store); 645 Handle<FixedArrayBase> backing_store);
646 646
647 virtual void SetCapacityAndLength(Handle<JSArray> array, int capacity, 647 static void GrowCapacityAndConvert(Handle<JSObject> obj, int capacity) {
648 int length) final {
649 ElementsAccessorSubclass::
650 SetFastElementsCapacityAndLength(array, capacity, length);
651 }
652
653 static void SetFastElementsCapacityAndLength(
654 Handle<JSObject> obj,
655 int capacity,
656 int length) {
657 UNIMPLEMENTED(); 648 UNIMPLEMENTED();
658 } 649 }
659 650
660 virtual void Delete(Handle<JSObject> obj, uint32_t key, 651 virtual void Delete(Handle<JSObject> obj, uint32_t key,
661 LanguageMode language_mode) override = 0; 652 LanguageMode language_mode) override = 0;
662 653
663 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 654 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
664 FixedArrayBase* to, ElementsKind from_kind, 655 FixedArrayBase* to, ElementsKind from_kind,
665 uint32_t to_start, int packed_size, 656 uint32_t to_start, int packed_size,
666 int copy_size) { 657 int copy_size) {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 CopyDoubleToObjectElements( 1005 CopyDoubleToObjectElements(
1015 from, from_start, to, to_kind, to_start, copy_size); 1006 from, from_start, to, to_kind, to_start, copy_size);
1016 break; 1007 break;
1017 } 1008 }
1018 case DICTIONARY_ELEMENTS: 1009 case DICTIONARY_ELEMENTS:
1019 CopyDictionaryToObjectElements(from, from_start, to, to_kind, to_start, 1010 CopyDictionaryToObjectElements(from, from_start, to, to_kind, to_start,
1020 copy_size); 1011 copy_size);
1021 break; 1012 break;
1022 case SLOPPY_ARGUMENTS_ELEMENTS: { 1013 case SLOPPY_ARGUMENTS_ELEMENTS: {
1023 // TODO(verwaest): This is a temporary hack to support extending 1014 // TODO(verwaest): This is a temporary hack to support extending
1024 // SLOPPY_ARGUMENTS_ELEMENTS in SetFastElementsCapacityAndLength. 1015 // SLOPPY_ARGUMENTS_ELEMENTS in GrowCapacityAndConvert.
1025 // This case should be UNREACHABLE(). 1016 // This case should be UNREACHABLE().
1026 FixedArray* parameter_map = FixedArray::cast(from); 1017 FixedArray* parameter_map = FixedArray::cast(from);
1027 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); 1018 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
1028 ElementsKind from_kind = ElementsKindForArray(arguments); 1019 ElementsKind from_kind = ElementsKindForArray(arguments);
1029 CopyElementsImpl(arguments, from_start, to, from_kind, 1020 CopyElementsImpl(arguments, from_start, to, from_kind,
1030 to_start, packed_size, copy_size); 1021 to_start, packed_size, copy_size);
1031 break; 1022 break;
1032 } 1023 }
1033 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ 1024 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1034 case EXTERNAL_##TYPE##_ELEMENTS: \ 1025 case EXTERNAL_##TYPE##_ELEMENTS: \
1035 case TYPE##_ELEMENTS: \ 1026 case TYPE##_ELEMENTS: \
1036 UNREACHABLE(); 1027 UNREACHABLE();
1037 TYPED_ARRAYS(TYPED_ARRAY_CASE) 1028 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1038 #undef TYPED_ARRAY_CASE 1029 #undef TYPED_ARRAY_CASE
1039 } 1030 }
1040 } 1031 }
1041 1032
1042 1033
1043 static void SetFastElementsCapacityAndLength( 1034 static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) {
1044 Handle<JSObject> obj,
1045 uint32_t capacity,
1046 uint32_t length) {
1047 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode = 1035 JSObject::SetFastElementsCapacitySmiMode set_capacity_mode =
1048 obj->HasFastSmiElements() 1036 obj->HasFastSmiElements()
1049 ? JSObject::kAllowSmiElements 1037 ? JSObject::kAllowSmiElements
1050 : JSObject::kDontAllowSmiElements; 1038 : JSObject::kDontAllowSmiElements;
1051 JSObject::SetFastElementsCapacityAndLength( 1039 JSObject::SetFastElementsCapacity(obj, capacity, set_capacity_mode);
1052 obj, capacity, length, set_capacity_mode);
1053 } 1040 }
1054 }; 1041 };
1055 1042
1056 1043
1057 class FastPackedSmiElementsAccessor 1044 class FastPackedSmiElementsAccessor
1058 : public FastSmiOrObjectElementsAccessor< 1045 : public FastSmiOrObjectElementsAccessor<
1059 FastPackedSmiElementsAccessor, 1046 FastPackedSmiElementsAccessor,
1060 ElementsKindTraits<FAST_SMI_ELEMENTS> > { 1047 ElementsKindTraits<FAST_SMI_ELEMENTS> > {
1061 public: 1048 public:
1062 explicit FastPackedSmiElementsAccessor(const char* name) 1049 explicit FastPackedSmiElementsAccessor(const char* name)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 1091
1105 template<typename FastElementsAccessorSubclass, 1092 template<typename FastElementsAccessorSubclass,
1106 typename KindTraits> 1093 typename KindTraits>
1107 class FastDoubleElementsAccessor 1094 class FastDoubleElementsAccessor
1108 : public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> { 1095 : public FastElementsAccessor<FastElementsAccessorSubclass, KindTraits> {
1109 public: 1096 public:
1110 explicit FastDoubleElementsAccessor(const char* name) 1097 explicit FastDoubleElementsAccessor(const char* name)
1111 : FastElementsAccessor<FastElementsAccessorSubclass, 1098 : FastElementsAccessor<FastElementsAccessorSubclass,
1112 KindTraits>(name) {} 1099 KindTraits>(name) {}
1113 1100
1114 static void SetFastElementsCapacityAndLength(Handle<JSObject> obj, 1101 static void GrowCapacityAndConvert(Handle<JSObject> obj, uint32_t capacity) {
1115 uint32_t capacity, 1102 JSObject::SetFastDoubleElementsCapacity(obj, capacity);
1116 uint32_t length) {
1117 JSObject::SetFastDoubleElementsCapacityAndLength(obj, capacity, length);
1118 } 1103 }
1119 1104
1120 protected: 1105 protected:
1121 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start, 1106 static void CopyElementsImpl(FixedArrayBase* from, uint32_t from_start,
1122 FixedArrayBase* to, ElementsKind from_kind, 1107 FixedArrayBase* to, ElementsKind from_kind,
1123 uint32_t to_start, int packed_size, 1108 uint32_t to_start, int packed_size,
1124 int copy_size) { 1109 int copy_size) {
1125 DisallowHeapAllocation no_allocation; 1110 DisallowHeapAllocation no_allocation;
1126 switch (from_kind) { 1111 switch (from_kind) {
1127 case FAST_SMI_ELEMENTS: 1112 case FAST_SMI_ELEMENTS:
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 *backing_store, capacity - length); 1657 *backing_store, capacity - length);
1673 } else { 1658 } else {
1674 // Otherwise, fill the unused tail with holes. 1659 // Otherwise, fill the unused tail with holes.
1675 for (uint32_t i = length; i < old_length; i++) { 1660 for (uint32_t i = length; i < old_length; i++) {
1676 BackingStore::cast(*backing_store)->set_the_hole(i); 1661 BackingStore::cast(*backing_store)->set_the_hole(i);
1677 } 1662 }
1678 } 1663 }
1679 } else { 1664 } else {
1680 // Check whether the backing store should be expanded. 1665 // Check whether the backing store should be expanded.
1681 capacity = Max(length, JSObject::NewElementsCapacity(capacity)); 1666 capacity = Max(length, JSObject::NewElementsCapacity(capacity));
1682 ElementsAccessorSubclass::SetFastElementsCapacityAndLength(array, capacity, 1667 ElementsAccessorSubclass::GrowCapacityAndConvert(array, capacity);
1683 length);
1684 } 1668 }
1685 1669
1686 array->set_length(Smi::FromInt(length)); 1670 array->set_length(Smi::FromInt(length));
1687 JSObject::ValidateElements(array); 1671 JSObject::ValidateElements(array);
1688 } 1672 }
1689 1673
1690 1674
1691 MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array, 1675 MaybeHandle<Object> ArrayConstructInitializeElements(Handle<JSArray> array,
1692 Arguments* args) { 1676 Arguments* args) {
1693 if (args->length() == 0) { 1677 if (args->length() == 0) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 break; 1757 break;
1774 } 1758 }
1775 1759
1776 array->set_elements(*elms); 1760 array->set_elements(*elms);
1777 array->set_length(Smi::FromInt(number_of_elements)); 1761 array->set_length(Smi::FromInt(number_of_elements));
1778 return array; 1762 return array;
1779 } 1763 }
1780 1764
1781 } // namespace internal 1765 } // namespace internal
1782 } // namespace v8 1766 } // namespace v8
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698