| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 x = ToString(x); | 665 x = ToString(x); |
| 666 y = ToString(y); | 666 y = ToString(y); |
| 667 if (x == y) return 0; | 667 if (x == y) return 0; |
| 668 else return x < y ? -1 : 1; | 668 else return x < y ? -1 : 1; |
| 669 }; | 669 }; |
| 670 | 670 |
| 671 function QuickSort(a, from, to) { | 671 function QuickSort(a, from, to) { |
| 672 if (from >= to - 1) return; | 672 if (from >= to - 1) return; |
| 673 var pivot_index = $floor($random() * (to - from)) + from; | 673 var pivot_index = $floor($random() * (to - from)) + from; |
| 674 var pivot = a[pivot_index]; | 674 var pivot = a[pivot_index]; |
| 675 a[pivot_index] = a[to - 1]; |
| 676 a[to - 1] = pivot; |
| 675 var low_end = from; // Upper bound of the elements lower than pivot. | 677 var low_end = from; // Upper bound of the elements lower than pivot. |
| 676 var high_start = to; // Lower bound of the elements greater than pivot. | 678 var high_start = to - 1; // Lower bound of the elements greater than pivot. |
| 677 for (var i = from; i < high_start; ) { | 679 for (var i = from; i < high_start; ) { |
| 678 var element = a[i]; | 680 var element = a[i]; |
| 679 var order = Compare(element, pivot); | 681 var order = Compare(element, pivot); |
| 680 if (order < 0) { | 682 if (order < 0) { |
| 681 a[i] = a[low_end]; | 683 a[i] = a[low_end]; |
| 682 a[low_end] = element; | 684 a[low_end] = element; |
| 683 low_end++; | 685 low_end++; |
| 684 i++; | 686 i++; |
| 685 } else if (order > 0) { | 687 } else if (order > 0) { |
| 686 high_start--; | 688 high_start--; |
| 687 a[i] = a[high_start]; | 689 a[i] = a[high_start]; |
| 688 a[high_start] = element; | 690 a[high_start] = element; |
| 689 } else { // order == 0 | 691 } else { // order == 0 |
| 690 i++; | 692 i++; |
| 691 } | 693 } |
| 692 } | 694 } |
| 695 a[to - 1] = a[high_start]; |
| 696 a[high_start] = pivot; |
| 697 high_start++; |
| 693 QuickSort(a, from, low_end); | 698 QuickSort(a, from, low_end); |
| 694 QuickSort(a, high_start, to); | 699 QuickSort(a, high_start, to); |
| 695 } | 700 } |
| 696 | 701 |
| 697 var old_length = ToUint32(this.length); | 702 var old_length = ToUint32(this.length); |
| 698 | 703 |
| 699 %RemoveArrayHoles(this); | 704 %RemoveArrayHoles(this); |
| 700 | 705 |
| 701 var length = ToUint32(this.length); | 706 var length = ToUint32(this.length); |
| 702 QuickSort(this, 0, length); | 707 QuickSort(this, 0, length); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 ArrayEvery: 1, | 908 ArrayEvery: 1, |
| 904 ArrayMap: 1, | 909 ArrayMap: 1, |
| 905 ArrayIndexOf: 1, | 910 ArrayIndexOf: 1, |
| 906 ArrayLastIndexOf: 1, | 911 ArrayLastIndexOf: 1, |
| 907 ArrayPush: 1 | 912 ArrayPush: 1 |
| 908 }); | 913 }); |
| 909 }; | 914 }; |
| 910 | 915 |
| 911 | 916 |
| 912 SetupArray(); | 917 SetupArray(); |
| OLD | NEW |