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

Side by Side Diff: src/runtime/runtime-typedarray.cc

Issue 2733393002: [typedarrays] check byte offset for fast typedarray sort (Closed)
Patch Set: Use DataPtr 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 | « no previous file | test/mjsunit/es6/typedarray-sort.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/messages.h" 9 #include "src/messages.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 368 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
369 isolate, array, JSTypedArray::Validate(isolate, target_obj, method)); 369 isolate, array, JSTypedArray::Validate(isolate, target_obj, method));
370 370
371 // This line can be removed when JSTypedArray::Validate throws 371 // This line can be removed when JSTypedArray::Validate throws
372 // if array.[[ViewedArrayBuffer]] is neutered(v8:4648) 372 // if array.[[ViewedArrayBuffer]] is neutered(v8:4648)
373 if (V8_UNLIKELY(array->WasNeutered())) return *array; 373 if (V8_UNLIKELY(array->WasNeutered())) return *array;
374 374
375 size_t length = array->length_value(); 375 size_t length = array->length_value();
376 if (length <= 1) return *array; 376 if (length <= 1) return *array;
377 377
378 Handle<FixedTypedArrayBase> elements(
379 FixedTypedArrayBase::cast(array->elements()));
378 switch (array->type()) { 380 switch (array->type()) {
379 #define TYPED_ARRAY_SORT(Type, type, TYPE, ctype, size) \ 381 #define TYPED_ARRAY_SORT(Type, type, TYPE, ctype, size) \
380 case kExternal##Type##Array: { \ 382 case kExternal##Type##Array: { \
381 ctype* backing_store = \ 383 ctype* data = static_cast<ctype*>(elements->DataPtr()); \
382 static_cast<ctype*>(array->GetBuffer()->backing_store()); \ 384 if (kExternal##Type##Array == kExternalFloat64Array || \
383 if (kExternal##Type##Array == kExternalFloat64Array || \ 385 kExternal##Type##Array == kExternalFloat32Array) \
384 kExternal##Type##Array == kExternalFloat32Array) \ 386 std::sort(data, data + length, CompareNum<ctype>); \
385 std::sort(backing_store, backing_store + length, CompareNum<ctype>); \ 387 else \
386 else \ 388 std::sort(data, data + length); \
387 std::sort(backing_store, backing_store + length); \ 389 break; \
388 break; \
389 } 390 }
390 391
391 TYPED_ARRAYS(TYPED_ARRAY_SORT) 392 TYPED_ARRAYS(TYPED_ARRAY_SORT)
392 #undef TYPED_ARRAY_SORT 393 #undef TYPED_ARRAY_SORT
393 } 394 }
394 395
395 return *array; 396 return *array;
396 } 397 }
397 398
398 RUNTIME_FUNCTION(Runtime_TypedArrayMaxSizeInHeap) { 399 RUNTIME_FUNCTION(Runtime_TypedArrayMaxSizeInHeap) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 return isolate->heap()->false_value(); 442 return isolate->heap()->false_value();
442 } 443 }
443 444
444 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); 445 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0]));
445 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && 446 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() &&
446 obj->type() == kExternalInt32Array); 447 obj->type() == kExternalInt32Array);
447 } 448 }
448 449
449 } // namespace internal 450 } // namespace internal
450 } // namespace v8 451 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/es6/typedarray-sort.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698