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

Side by Side Diff: src/js/typedarray.js

Issue 2693043009: [typedarrays] sort in C++ for undefined comparefn (Closed)
Patch Set: [typedarrays] sort in C++ for no comparison function 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/builtins/builtins-typedarray.cc ('k') | src/objects.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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 510
511 // ES6 draft 05-18-15, section 22.2.3.21 511 // ES6 draft 05-18-15, section 22.2.3.21
512 function TypedArrayReverse() { 512 function TypedArrayReverse() {
513 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 513 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
514 514
515 var length = %_TypedArrayGetLength(this); 515 var length = %_TypedArrayGetLength(this);
516 516
517 return PackedArrayReverse(this, length); 517 return PackedArrayReverse(this, length);
518 } 518 }
519 519
520
521 function TypedArrayComparefn(x, y) {
522 if (x === 0 && x === y) {
523 x = 1 / x;
524 y = 1 / y;
525 }
526 if (x < y) {
527 return -1;
528 } else if (x > y) {
529 return 1;
530 } else if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) {
531 return NUMBER_IS_NAN(y) ? 0 : 1;
532 } else if (NUMBER_IS_NAN(x)) {
533 return 1;
534 }
535 return 0;
536 }
537
538
539 // ES6 draft 05-18-15, section 22.2.3.25 520 // ES6 draft 05-18-15, section 22.2.3.25
540 function TypedArraySort(comparefn) { 521 function TypedArraySort(comparefn) {
541 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 522 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
542 523
543 var length = %_TypedArrayGetLength(this); 524 var length = %_TypedArrayGetLength(this);
544 525
545 if (IS_UNDEFINED(comparefn)) { 526 if (IS_UNDEFINED(comparefn)) {
546 comparefn = TypedArrayComparefn; 527 return %TypedArraySortFast(this);
547 } 528 }
548 529
549 return InnerArraySort(this, length, comparefn); 530 return InnerArraySort(this, length, comparefn);
550 } 531 }
551 532
552 533
553 // ES6 section 22.2.3.13 534 // ES6 section 22.2.3.13
554 function TypedArrayIndexOf(element, index) { 535 function TypedArrayIndexOf(element, index) {
555 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 536 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
556 537
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 %AddNamedProperty(GlobalNAME.prototype, 861 %AddNamedProperty(GlobalNAME.prototype,
881 "constructor", global.NAME, DONT_ENUM); 862 "constructor", global.NAME, DONT_ENUM);
882 %AddNamedProperty(GlobalNAME.prototype, 863 %AddNamedProperty(GlobalNAME.prototype,
883 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 864 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
884 READ_ONLY | DONT_ENUM | DONT_DELETE); 865 READ_ONLY | DONT_ENUM | DONT_DELETE);
885 endmacro 866 endmacro
886 867
887 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 868 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
888 869
889 }) 870 })
OLDNEW
« no previous file with comments | « src/builtins/builtins-typedarray.cc ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698