OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 var high_start = to - 1; // Lower bound of elements greater than pivot. | 816 var high_start = to - 1; // Lower bound of elements greater than pivot. |
817 a[middle_index] = a[low_end]; | 817 a[middle_index] = a[low_end]; |
818 a[low_end] = pivot; | 818 a[low_end] = pivot; |
819 | 819 |
820 // From low_end to i are elements equal to pivot. | 820 // From low_end to i are elements equal to pivot. |
821 // From i to high_start are elements that haven't been compared yet. | 821 // From i to high_start are elements that haven't been compared yet. |
822 partition: for (var i = low_end + 1; i < high_start; i++) { | 822 partition: for (var i = low_end + 1; i < high_start; i++) { |
823 var element = a[i]; | 823 var element = a[i]; |
824 var order = %_CallFunction(receiver, element, pivot, comparefn); | 824 var order = %_CallFunction(receiver, element, pivot, comparefn); |
825 if (order < 0) { | 825 if (order < 0) { |
826 %_SwapElements(a, i, low_end); | 826 a[i] = a[low_end]; |
| 827 a[low_end] = element; |
827 low_end++; | 828 low_end++; |
828 } else if (order > 0) { | 829 } else if (order > 0) { |
829 do { | 830 do { |
830 high_start--; | 831 high_start--; |
831 if (high_start == i) break partition; | 832 if (high_start == i) break partition; |
832 var top_elem = a[high_start]; | 833 var top_elem = a[high_start]; |
833 order = %_CallFunction(receiver, top_elem, pivot, comparefn); | 834 order = %_CallFunction(receiver, top_elem, pivot, comparefn); |
834 } while (order > 0); | 835 } while (order > 0); |
835 %_SwapElements(a, i, high_start); | 836 a[i] = a[high_start]; |
| 837 a[high_start] = element; |
836 if (order < 0) { | 838 if (order < 0) { |
837 %_SwapElements(a, i, low_end); | 839 element = a[i]; |
| 840 a[i] = a[low_end]; |
| 841 a[low_end] = element; |
838 low_end++; | 842 low_end++; |
839 } | 843 } |
840 } | 844 } |
841 } | 845 } |
842 QuickSort(a, from, low_end); | 846 QuickSort(a, from, low_end); |
843 QuickSort(a, high_start, to); | 847 QuickSort(a, high_start, to); |
844 } | 848 } |
845 | 849 |
846 // Copy elements in the range 0..length from obj's prototype chain | 850 // Copy elements in the range 0..length from obj's prototype chain |
847 // to obj itself, if obj has holes. Return one more than the maximal index | 851 // to obj itself, if obj has holes. Return one more than the maximal index |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 // exposed to user code. | 1422 // exposed to user code. |
1419 // Adding only the functions that are actually used. | 1423 // Adding only the functions that are actually used. |
1420 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1424 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
1421 "join", getFunction("join", ArrayJoin), | 1425 "join", getFunction("join", ArrayJoin), |
1422 "pop", getFunction("pop", ArrayPop), | 1426 "pop", getFunction("pop", ArrayPop), |
1423 "push", getFunction("push", ArrayPush) | 1427 "push", getFunction("push", ArrayPush) |
1424 )); | 1428 )); |
1425 } | 1429 } |
1426 | 1430 |
1427 SetUpArray(); | 1431 SetUpArray(); |
OLD | NEW |