OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 var high_start = to - 1; // Lower bound of elements greater than pivot. | 820 var high_start = to - 1; // Lower bound of elements greater than pivot. |
821 a[middle_index] = a[low_end]; | 821 a[middle_index] = a[low_end]; |
822 a[low_end] = pivot; | 822 a[low_end] = pivot; |
823 | 823 |
824 // From low_end to i are elements equal to pivot. | 824 // From low_end to i are elements equal to pivot. |
825 // From i to high_start are elements that haven't been compared yet. | 825 // From i to high_start are elements that haven't been compared yet. |
826 partition: for (var i = low_end + 1; i < high_start; i++) { | 826 partition: for (var i = low_end + 1; i < high_start; i++) { |
827 var element = a[i]; | 827 var element = a[i]; |
828 var order = %_CallFunction(receiver, element, pivot, comparefn); | 828 var order = %_CallFunction(receiver, element, pivot, comparefn); |
829 if (order < 0) { | 829 if (order < 0) { |
830 %_SwapElements(a, i, low_end); | 830 a[i] = a[low_end]; |
| 831 a[low_end] = element; |
831 low_end++; | 832 low_end++; |
832 } else if (order > 0) { | 833 } else if (order > 0) { |
833 do { | 834 do { |
834 high_start--; | 835 high_start--; |
835 if (high_start == i) break partition; | 836 if (high_start == i) break partition; |
836 var top_elem = a[high_start]; | 837 var top_elem = a[high_start]; |
837 order = %_CallFunction(receiver, top_elem, pivot, comparefn); | 838 order = %_CallFunction(receiver, top_elem, pivot, comparefn); |
838 } while (order > 0); | 839 } while (order > 0); |
839 %_SwapElements(a, i, high_start); | 840 a[i] = a[high_start]; |
| 841 a[high_start] = element; |
840 if (order < 0) { | 842 if (order < 0) { |
841 %_SwapElements(a, i, low_end); | 843 element = a[i]; |
| 844 a[i] = a[low_end]; |
| 845 a[low_end] = element; |
842 low_end++; | 846 low_end++; |
843 } | 847 } |
844 } | 848 } |
845 } | 849 } |
846 QuickSort(a, from, low_end); | 850 QuickSort(a, from, low_end); |
847 QuickSort(a, high_start, to); | 851 QuickSort(a, high_start, to); |
848 }; | 852 }; |
849 | 853 |
850 // Copy elements in the range 0..length from obj's prototype chain | 854 // Copy elements in the range 0..length from obj's prototype chain |
851 // to obj itself, if obj has holes. Return one more than the maximal index | 855 // to obj itself, if obj has holes. Return one more than the maximal index |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 // exposed to user code. | 1524 // exposed to user code. |
1521 // Adding only the functions that are actually used. | 1525 // Adding only the functions that are actually used. |
1522 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1526 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
1523 "join", getFunction("join", ArrayJoin), | 1527 "join", getFunction("join", ArrayJoin), |
1524 "pop", getFunction("pop", ArrayPop), | 1528 "pop", getFunction("pop", ArrayPop), |
1525 "push", getFunction("push", ArrayPush) | 1529 "push", getFunction("push", ArrayPush) |
1526 )); | 1530 )); |
1527 } | 1531 } |
1528 | 1532 |
1529 SetUpArray(); | 1533 SetUpArray(); |
OLD | NEW |