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

Side by Side Diff: src/elements.cc

Issue 2735563002: Migrate %TypedArray%.prototype.fill to C++ (Closed)
Patch Set: Merge branch 'master' into fill Created 3 years, 9 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/js/array.js » ('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/elements.h" 5 #include "src/elements.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/factory.h" 9 #include "src/factory.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } cmp; 463 } cmp;
464 Object** start = 464 Object** start =
465 reinterpret_cast<Object**>(indices->GetFirstElementAddress()); 465 reinterpret_cast<Object**>(indices->GetFirstElementAddress());
466 std::sort(start, start + sort_size, cmp); 466 std::sort(start, start + sort_size, cmp);
467 if (write_barrier_mode != SKIP_WRITE_BARRIER) { 467 if (write_barrier_mode != SKIP_WRITE_BARRIER) {
468 FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(indices->GetIsolate()->heap(), *indices, 468 FIXED_ARRAY_ELEMENTS_WRITE_BARRIER(indices->GetIsolate()->heap(), *indices,
469 0, sort_size); 469 0, sort_size);
470 } 470 }
471 } 471 }
472 472
473 static Object* FillNumberSlowPath(Isolate* isolate, Handle<JSTypedArray> array,
474 Handle<Object> obj_value,
475 uint32_t start, uint32_t end) {
476 Handle<Object> cast_value;
477 ElementsAccessor* elements = array->GetElementsAccessor();
478
479 for (uint32_t k = start; k < end; ++k) {
480 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
481 isolate, cast_value, Object::ToNumber(obj_value));
ulan 2017/03/22 10:10:54 Shouldn't this be hoisted outside the loop? Other
rongjie 2017/03/22 10:15:02 Please see cbruni@ explanation at https://coderevi
482 // TODO(caitp,cbruni): throw on neutered array
483 if (V8_UNLIKELY(array->WasNeutered())) return *array;
484 elements->Set(array, k, *cast_value);
485 }
486 return *array;
487 }
488
473 static Maybe<bool> IncludesValueSlowPath(Isolate* isolate, 489 static Maybe<bool> IncludesValueSlowPath(Isolate* isolate,
474 Handle<JSObject> receiver, 490 Handle<JSObject> receiver,
475 Handle<Object> value, 491 Handle<Object> value,
476 uint32_t start_from, uint32_t length) { 492 uint32_t start_from, uint32_t length) {
477 bool search_for_hole = value->IsUndefined(isolate); 493 bool search_for_hole = value->IsUndefined(isolate);
478 for (uint32_t k = start_from; k < length; ++k) { 494 for (uint32_t k = start_from; k < length; ++k) {
479 LookupIterator it(isolate, receiver, k); 495 LookupIterator it(isolate, receiver, k);
480 if (!it.IsFound()) { 496 if (!it.IsFound()) {
481 if (search_for_hole) return Just(true); 497 if (search_for_hole) return Just(true);
482 continue; 498 continue;
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 1200
1185 static uint32_t GetCapacityImpl(JSObject* holder, 1201 static uint32_t GetCapacityImpl(JSObject* holder,
1186 FixedArrayBase* backing_store) { 1202 FixedArrayBase* backing_store) {
1187 return backing_store->length(); 1203 return backing_store->length();
1188 } 1204 }
1189 1205
1190 uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final { 1206 uint32_t GetCapacity(JSObject* holder, FixedArrayBase* backing_store) final {
1191 return Subclass::GetCapacityImpl(holder, backing_store); 1207 return Subclass::GetCapacityImpl(holder, backing_store);
1192 } 1208 }
1193 1209
1210 static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver,
1211 Handle<Object> obj_value, uint32_t start,
1212 uint32_t end) {
1213 UNREACHABLE();
1214 return *receiver;
1215 }
1216
1217 Object* Fill(Isolate* isolate, Handle<JSObject> receiver,
1218 Handle<Object> obj_value, uint32_t start, uint32_t end) {
1219 return Subclass::FillImpl(isolate, receiver, obj_value, start, end);
1220 }
1221
1194 static Maybe<bool> IncludesValueImpl(Isolate* isolate, 1222 static Maybe<bool> IncludesValueImpl(Isolate* isolate,
1195 Handle<JSObject> receiver, 1223 Handle<JSObject> receiver,
1196 Handle<Object> value, 1224 Handle<Object> value,
1197 uint32_t start_from, uint32_t length) { 1225 uint32_t start_from, uint32_t length) {
1198 return IncludesValueSlowPath(isolate, receiver, value, start_from, length); 1226 return IncludesValueSlowPath(isolate, receiver, value, start_from, length);
1199 } 1227 }
1200 1228
1201 Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver, 1229 Maybe<bool> IncludesValue(Isolate* isolate, Handle<JSObject> receiver,
1202 Handle<Object> value, uint32_t start_from, 1230 Handle<Object> value, uint32_t start_from,
1203 uint32_t length) final { 1231 uint32_t length) final {
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
2822 if (get_entries) { 2850 if (get_entries) {
2823 value = MakeEntryPair(isolate, index, value); 2851 value = MakeEntryPair(isolate, index, value);
2824 } 2852 }
2825 values_or_entries->set(count++, *value); 2853 values_or_entries->set(count++, *value);
2826 } 2854 }
2827 } 2855 }
2828 *nof_items = count; 2856 *nof_items = count;
2829 return Just(true); 2857 return Just(true);
2830 } 2858 }
2831 2859
2860 static Object* FillImpl(Isolate* isolate, Handle<JSObject> receiver,
2861 Handle<Object> obj_value, uint32_t start,
2862 uint32_t end) {
2863 Handle<JSTypedArray> array = Handle<JSTypedArray>::cast(receiver);
2864 DCHECK(!array->WasNeutered());
2865
2866 if (!obj_value->IsNumber()) {
2867 return FillNumberSlowPath(isolate, array, obj_value, start, end);
2868 }
2869
2870 ctype value = 0;
2871 if (obj_value->IsSmi()) {
2872 value = BackingStore::from_int(Smi::cast(*obj_value)->value());
2873 } else {
2874 DCHECK(obj_value->IsHeapNumber());
2875 value = BackingStore::from_double(HeapNumber::cast(*obj_value)->value());
2876 }
2877
2878 // Ensure indexes are within array bounds
2879 DCHECK_LE(0, start);
2880 DCHECK_LE(start, end);
2881 DCHECK_LE(end, array->length_value());
2882
2883 DisallowHeapAllocation no_gc;
2884 BackingStore* elements = BackingStore::cast(receiver->elements());
2885 ctype* data = static_cast<ctype*>(elements->DataPtr());
2886 std::fill(data + start, data + end, value);
2887 return *array;
2888 }
2889
2832 static Maybe<bool> IncludesValueImpl(Isolate* isolate, 2890 static Maybe<bool> IncludesValueImpl(Isolate* isolate,
2833 Handle<JSObject> receiver, 2891 Handle<JSObject> receiver,
2834 Handle<Object> value, 2892 Handle<Object> value,
2835 uint32_t start_from, uint32_t length) { 2893 uint32_t start_from, uint32_t length) {
2836 DisallowHeapAllocation no_gc; 2894 DisallowHeapAllocation no_gc;
2837 2895
2838 // TODO(caitp): return Just(false) here when implementing strict throwing on 2896 // TODO(caitp): return Just(false) here when implementing strict throwing on
2839 // neutered views. 2897 // neutered views.
2840 if (WasNeutered(*receiver)) { 2898 if (WasNeutered(*receiver)) {
2841 return Just(value->IsUndefined(isolate) && length > start_from); 2899 return Just(value->IsUndefined(isolate) && length > start_from);
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
3918 insertion_index += len; 3976 insertion_index += len;
3919 } 3977 }
3920 3978
3921 DCHECK_EQ(insertion_index, result_len); 3979 DCHECK_EQ(insertion_index, result_len);
3922 return result_array; 3980 return result_array;
3923 } 3981 }
3924 3982
3925 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 3983 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
3926 } // namespace internal 3984 } // namespace internal
3927 } // namespace v8 3985 } // namespace v8
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/js/array.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698