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

Side by Side Diff: src/elements.cc

Issue 416403002: Keep new arrays allocated with 'new Array(N)' in fast mode (revisited) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review feedback Created 6 years, 5 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/array.js ('k') | 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/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/objects.h" 10 #include "src/objects.h"
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 public: 890 public:
891 explicit FastElementsAccessor(const char* name) 891 explicit FastElementsAccessor(const char* name)
892 : ElementsAccessorBase<FastElementsAccessorSubclass, 892 : ElementsAccessorBase<FastElementsAccessorSubclass,
893 KindTraits>(name) {} 893 KindTraits>(name) {}
894 protected: 894 protected:
895 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>; 895 friend class ElementsAccessorBase<FastElementsAccessorSubclass, KindTraits>;
896 friend class SloppyArgumentsElementsAccessor; 896 friend class SloppyArgumentsElementsAccessor;
897 897
898 typedef typename KindTraits::BackingStore BackingStore; 898 typedef typename KindTraits::BackingStore BackingStore;
899 899
900 // Adjusts the length of the fast backing store or returns the new length or 900 // Adjusts the length of the fast backing store.
901 // undefined in case conversion to a slow backing store should be performed.
902 static Handle<Object> SetLengthWithoutNormalize( 901 static Handle<Object> SetLengthWithoutNormalize(
903 Handle<FixedArrayBase> backing_store, 902 Handle<FixedArrayBase> backing_store,
904 Handle<JSArray> array, 903 Handle<JSArray> array,
905 Handle<Object> length_object, 904 Handle<Object> length_object,
906 uint32_t length) { 905 uint32_t length) {
907 Isolate* isolate = array->GetIsolate(); 906 Isolate* isolate = array->GetIsolate();
908 uint32_t old_capacity = backing_store->length(); 907 uint32_t old_capacity = backing_store->length();
909 Handle<Object> old_length(array->length(), isolate); 908 Handle<Object> old_length(array->length(), isolate);
910 bool same_or_smaller_size = old_length->IsSmi() && 909 bool same_or_smaller_size = old_length->IsSmi() &&
911 static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length; 910 static_cast<uint32_t>(Handle<Smi>::cast(old_length)->value()) >= length;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 for (int i = length; i < old_length; i++) { 942 for (int i = length; i < old_length; i++) {
944 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); 943 Handle<BackingStore>::cast(backing_store)->set_the_hole(i);
945 } 944 }
946 } 945 }
947 return length_object; 946 return length_object;
948 } 947 }
949 948
950 // Check whether the backing store should be expanded. 949 // Check whether the backing store should be expanded.
951 uint32_t min = JSObject::NewElementsCapacity(old_capacity); 950 uint32_t min = JSObject::NewElementsCapacity(old_capacity);
952 uint32_t new_capacity = length > min ? length : min; 951 uint32_t new_capacity = length > min ? length : min;
953 if (!array->ShouldConvertToSlowElements(new_capacity)) { 952 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength(
954 FastElementsAccessorSubclass::SetFastElementsCapacityAndLength( 953 array, new_capacity, length);
955 array, new_capacity, length); 954 JSObject::ValidateElements(array);
956 JSObject::ValidateElements(array); 955 return length_object;
957 return length_object;
958 }
959
960 // Request conversion to slow elements.
961 return isolate->factory()->undefined_value();
962 } 956 }
963 957
964 static Handle<Object> DeleteCommon(Handle<JSObject> obj, 958 static Handle<Object> DeleteCommon(Handle<JSObject> obj,
965 uint32_t key, 959 uint32_t key,
966 JSReceiver::DeleteMode mode) { 960 JSReceiver::DeleteMode mode) {
967 ASSERT(obj->HasFastSmiOrObjectElements() || 961 ASSERT(obj->HasFastSmiOrObjectElements() ||
968 obj->HasFastDoubleElements() || 962 obj->HasFastDoubleElements() ||
969 obj->HasFastArgumentsElements()); 963 obj->HasFastArgumentsElements());
970 Isolate* isolate = obj->GetIsolate(); 964 Isolate* isolate = obj->GetIsolate();
971 Heap* heap = obj->GetHeap(); 965 Heap* heap = obj->GetHeap();
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 UNREACHABLE(); 1984 UNREACHABLE();
1991 break; 1985 break;
1992 } 1986 }
1993 1987
1994 array->set_elements(*elms); 1988 array->set_elements(*elms);
1995 array->set_length(Smi::FromInt(number_of_elements)); 1989 array->set_length(Smi::FromInt(number_of_elements));
1996 return array; 1990 return array;
1997 } 1991 }
1998 1992
1999 } } // namespace v8::internal 1993 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698