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

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

Issue 2693043009: [typedarrays] sort in C++ for undefined comparefn (Closed)
Patch Set: Split tests and codes Created 3 years, 10 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/runtime/runtime.h ('k') | no next file » | 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 target_base + target_byte_length > source_base)) { 360 target_base + target_byte_length > source_base)) {
361 // We do not support overlapping ArrayBuffers 361 // We do not support overlapping ArrayBuffers
362 DCHECK(target->GetBuffer()->backing_store() == 362 DCHECK(target->GetBuffer()->backing_store() ==
363 source->GetBuffer()->backing_store()); 363 source->GetBuffer()->backing_store());
364 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING); 364 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING);
365 } else { // Non-overlapping typed arrays 365 } else { // Non-overlapping typed arrays
366 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING); 366 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING);
367 } 367 }
368 } 368 }
369 369
370 namespace {
371
372 #define TYPED_ARRAY_SORT_COMPAREFN(Type, type, TYPE, ctype, size) \
373 bool compare##Type(ctype x, ctype y) { \
374 if (x < y) { \
375 return true; \
376 } else if (x > y) { \
377 return false; \
378 } else if (x == 0 && x == y) { \
379 return std::signbit(x) ? true : false; \
380 } else if (std::isnan(x)) { \
381 return false; \
382 } \
383 return true; \
384 }
385
386 TYPED_ARRAYS(TYPED_ARRAY_SORT_COMPAREFN)
387 #undef TYPED_ARRAY_SORT_COMPAREFN
388
389 } // namespace
390
391 RUNTIME_FUNCTION(Runtime_TypedArraySortFast) {
392 HandleScope scope(isolate);
393 DCHECK_EQ(1, args.length());
394
395 if (!args[0]->IsJSTypedArray()) {
396 THROW_NEW_ERROR_RETURN_FAILURE(
397 isolate, NewTypeError(MessageTemplate::kNotTypedArray));
398 }
399
400 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0);
401
402 Handle<JSTypedArray> array = Handle<JSTypedArray>::cast(target_obj);
403
404 if (array->WasNeutered()) {
405 THROW_NEW_ERROR_RETURN_FAILURE(
caitp 2017/02/15 12:24:20 So, as Dan was saying, we probably want to jist ea
caitp 2017/02/15 13:27:22 To add to this, maybe move ValidateTypedArray() in
Choongwoo Han 2017/02/16 08:06:34 Done. I've moved it to static inline method of JST
406 isolate, NewTypeError(MessageTemplate::kNotTypedArray));
407 }
408
409 size_t length = array->length_value();
410 if (length == 0) return *array;
411
412 switch (array->type()) {
413 #define TYPED_ARRAY_SORT(Type, type, TYPE, ctype, size) \
414 case kExternal##Type##Array: { \
415 ctype* backing_store = \
416 static_cast<ctype*>(array->GetBuffer()->backing_store()); \
417 std::sort(backing_store, backing_store + length, compare##Type); \
418 break; \
419 }
420
421 TYPED_ARRAYS(TYPED_ARRAY_SORT)
422 #undef TYPED_ARRAY_SORT
423 }
424
425 return *array;
426 }
370 427
371 RUNTIME_FUNCTION(Runtime_TypedArrayMaxSizeInHeap) { 428 RUNTIME_FUNCTION(Runtime_TypedArrayMaxSizeInHeap) {
372 DCHECK_EQ(0, args.length()); 429 DCHECK_EQ(0, args.length());
373 DCHECK_OBJECT_SIZE(FLAG_typed_array_max_size_in_heap + 430 DCHECK_OBJECT_SIZE(FLAG_typed_array_max_size_in_heap +
374 FixedTypedArrayBase::kDataOffset); 431 FixedTypedArrayBase::kDataOffset);
375 return Smi::FromInt(FLAG_typed_array_max_size_in_heap); 432 return Smi::FromInt(FLAG_typed_array_max_size_in_heap);
376 } 433 }
377 434
378 435
379 RUNTIME_FUNCTION(Runtime_IsTypedArray) { 436 RUNTIME_FUNCTION(Runtime_IsTypedArray) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 return isolate->heap()->false_value(); 471 return isolate->heap()->false_value();
415 } 472 }
416 473
417 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0])); 474 Handle<JSTypedArray> obj(JSTypedArray::cast(args[0]));
418 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() && 475 return isolate->heap()->ToBoolean(obj->GetBuffer()->is_shared() &&
419 obj->type() == kExternalInt32Array); 476 obj->type() == kExternalInt32Array);
420 } 477 }
421 478
422 } // namespace internal 479 } // namespace internal
423 } // namespace v8 480 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698