about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimon BD <simon@server>2012-09-27 19:05:13 -0500
committerSimon BD <simon@server>2012-09-27 19:05:13 -0500
commit868d10160f81c9d836202ed1c0683b75730fe73d (patch)
treec2959717ffb02907a1cfe6cd559d54a396ad8cb7
parentf98f00f7f6afac993fd2a08e7135bfdb8e70dec6 (diff)
downloadrust-868d10160f81c9d836202ed1c0683b75730fe73d.tar.gz
rust-868d10160f81c9d836202ed1c0683b75730fe73d.zip
Put function argument last in sort function. Fixes #3265.
-rw-r--r--src/cargo/cargo.rs2
-rw-r--r--src/libstd/json.rs2
-rw-r--r--src/libstd/sort.rs56
-rw-r--r--src/libstd/test.rs4
-rw-r--r--src/libsyntax/attr.rs2
-rw-r--r--src/libsyntax/ext/qquote.rs2
-rw-r--r--src/rustc/metadata/cstore.rs2
-rw-r--r--src/rustc/metadata/encoder.rs2
-rw-r--r--src/rustdoc/sort_pass.rs2
9 files changed, 42 insertions, 32 deletions
diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs
index 4dcfc608e0e..a9fa6ca899c 100644
--- a/src/cargo/cargo.rs
+++ b/src/cargo/cargo.rs
@@ -1498,7 +1498,7 @@ fn print_pkg(s: source, p: package) {
 fn print_source(s: source) {
     info(s.name + ~" (" + s.url + ~")");
 
-    let pks = sort::merge_sort(sys::shape_lt, s.packages.get());
+    let pks = sort::merge_sort(s.packages.get(), sys::shape_lt);
     let l = vec::len(pks);
 
     print(io::with_str_writer(|writer| {
diff --git a/src/libstd/json.rs b/src/libstd/json.rs
index 0f7bec6344a..0094b5a9277 100644
--- a/src/libstd/json.rs
+++ b/src/libstd/json.rs
@@ -145,7 +145,7 @@ fn to_writer_pretty(wr: io::Writer, j: Json, indent: uint) {
         }
 
         // sort by key strings
-        let sorted_pairs = sort::merge_sort(|a,b| *a <= *b, pairs);
+        let sorted_pairs = do sort::merge_sort(pairs) |a,b| { *a <= *b };
 
         // {
         wr.write_str(~"{\n");
diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs
index 4f8102515ce..e0e35f68da2 100644
--- a/src/libstd/sort.rs
+++ b/src/libstd/sort.rs
@@ -20,12 +20,12 @@ type Le<T> = pure fn(v1: &T, v2: &T) -> bool;
  * Has worst case O(n log n) performance, best case O(n), but
  * is not space efficient. This is a stable sort.
  */
-fn merge_sort<T: Copy>(le: Le<T>, v: &[const T]) -> ~[T] {
+fn merge_sort<T: Copy>(v: &[const T], le: Le<T>) -> ~[T] {
     type Slice = (uint, uint);
 
-    return merge_sort_(le, v, (0u, len(v)));
+    return merge_sort_(v, (0u, len(v)), le);
 
-    fn merge_sort_<T: Copy>(le: Le<T>, v: &[const T], slice: Slice)
+    fn merge_sort_<T: Copy>(v: &[const T], slice: Slice, le: Le<T>)
         -> ~[T] {
         let begin = slice.first();
         let end = slice.second();
@@ -37,7 +37,7 @@ fn merge_sort<T: Copy>(le: Le<T>, v: &[const T]) -> ~[T] {
         let mid = v_len / 2u + begin;
         let a = (begin, mid);
         let b = (mid, end);
-        return merge(le, merge_sort_(le, v, a), merge_sort_(le, v, b));
+        return merge(le, merge_sort_(v, a, le), merge_sort_(v, b, le));
     }
 
     fn merge<T: Copy>(le: Le<T>, a: &[T], b: &[T]) -> ~[T] {
@@ -58,8 +58,8 @@ fn merge_sort<T: Copy>(le: Le<T>, v: &[const T]) -> ~[T] {
     }
 }
 
-fn part<T: Copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
-                right: uint, pivot: uint) -> uint {
+fn part<T: Copy>(arr: &[mut T], left: uint,
+                right: uint, pivot: uint, compare_func: Le<T>) -> uint {
     let pivot_value = arr[pivot];
     arr[pivot] <-> arr[right];
     let mut storage_index: uint = left;
@@ -75,16 +75,16 @@ fn part<T: Copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
     return storage_index;
 }
 
-fn qsort<T: Copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
-             right: uint) {
+fn qsort<T: Copy>(arr: &[mut T], left: uint,
+             right: uint, compare_func: Le<T>) {
     if right > left {
         let pivot = (left + right) / 2u;
-        let new_pivot = part::<T>(compare_func, arr, left, right, pivot);
+        let new_pivot = part::<T>(arr, left, right, pivot, compare_func);
         if new_pivot != 0u {
             // Need to do this check before recursing due to overflow
-            qsort::<T>(compare_func, arr, left, new_pivot - 1u);
+            qsort::<T>(arr, left, new_pivot - 1u, compare_func);
         }
-        qsort::<T>(compare_func, arr, new_pivot + 1u, right);
+        qsort::<T>(arr, new_pivot + 1u, right, compare_func);
     }
 }
 
@@ -94,9 +94,9 @@ fn qsort<T: Copy>(compare_func: Le<T>, arr: &[mut T], left: uint,
  * Has worst case O(n^2) performance, average case O(n log n).
  * This is an unstable sort.
  */
-fn quick_sort<T: Copy>(compare_func: Le<T>, arr: &[mut T]) {
+fn quick_sort<T: Copy>(arr: &[mut T], compare_func: Le<T>) {
     if len::<T>(arr) == 0u { return; }
-    qsort::<T>(compare_func, arr, 0u, len::<T>(arr) - 1u);
+    qsort::<T>(arr, 0u, len::<T>(arr) - 1u, compare_func);
 }
 
 fn qsort3<T: Copy Ord Eq>(arr: &[mut T], left: int, right: int) {
@@ -292,7 +292,8 @@ fn countRunAndMakeAscending<T: Ord>(array: &[mut T]) -> uint {
     return run;
 }
 
-pure fn gallopLeft<T: Ord>(key: &const T, array: &[const T], hint: uint) -> uint {  
+pure fn gallopLeft<T: Ord>(key: &const T, array: &[const T],
+                            hint: uint) -> uint {  
     let size = array.len();
     assert size != 0 && hint < size;
 
@@ -340,7 +341,8 @@ pure fn gallopLeft<T: Ord>(key: &const T, array: &[const T], hint: uint) -> uint
     return ofs;
 }
 
-pure fn gallopRight<T: Ord>(key: &const T, array: &[const T], hint: uint) -> uint {
+pure fn gallopRight<T: Ord>(key: &const T, array: &[const T],
+                            hint: uint) -> uint {
     let size = array.len();
     assert size != 0 && hint < size;
 
@@ -464,7 +466,8 @@ impl<T: Ord> &MergeState<T> {
         self.runs.pop();
     }
 
-    fn mergeLo(array: &[mut T], base1: uint, len1: uint, base2: uint, len2: uint) {
+    fn mergeLo(array: &[mut T], base1: uint, len1: uint,
+                base2: uint, len2: uint) {
         assert len1 != 0 && len2 != 0 && base1+len1 == base2;
         
         vec::reserve(&mut self.tmp, len1);
@@ -558,7 +561,9 @@ impl<T: Ord> &MergeState<T> {
                 dest += 1; c1 += 1; len1 -= 1;
                 if len1 == 1 { breakOuter = true; break; }
                 minGallop -= 1;
-                if !(count1 >= MIN_GALLOP || count2 >= MIN_GALLOP) { break; } 
+                if !(count1 >= MIN_GALLOP || count2 >= MIN_GALLOP) {
+                    break;
+                } 
             }
             if breakOuter { break; }
             if minGallop < 0 { minGallop = 0; }
@@ -584,7 +589,8 @@ impl<T: Ord> &MergeState<T> {
         unsafe { vec::raw::set_len(self.tmp, 0); }
     }
 
-    fn mergeHi(array: &[mut T], base1: uint, len1: uint, base2: uint, len2: uint) {
+    fn mergeHi(array: &[mut T], base1: uint, len1: uint,
+                base2: uint, len2: uint) {
         assert len1 != 1 && len2 != 0 && base1 + len1 == base2;
 
         vec::reserve(&mut self.tmp, len2);
@@ -655,7 +661,8 @@ impl<T: Ord> &MergeState<T> {
                 assert len2 > 1 && len1 != 0;
 
                 let tmpView = vec::mut_view(array, base1, base1+len1);
-                count1 = len1-gallopRight(&const self.tmp[c2], tmpView, len1-1);
+                count1 = len1 - gallopRight(
+                    &const self.tmp[c2], tmpView, len1-1);
 
                 if count1 != 0 {
                     dest -= count1; c1 -= count1; len1 -= count1;
@@ -670,8 +677,8 @@ impl<T: Ord> &MergeState<T> {
                 if len2 == 1 { breakOuter = true; break; }
 
                 let tmpView = vec::mut_view(self.tmp, 0, len2);
-                let gL = gallopLeft(&const array[c1], tmpView, len2-1);
-                count2 = len2 - gL;
+                let count2 = len2 - gallopLeft(
+                    &const array[c1], tmpView, len2-1);
                 if count2 != 0 {
                     dest -= count2; c2 -= count2; len2 -= count2;
                     unsafe {
@@ -683,7 +690,9 @@ impl<T: Ord> &MergeState<T> {
                 dest -= 1; c1 -= 1; len1 -= 1;
                 if len1 == 0 { breakOuter = true; break; }
                 minGallop -= 1;
-                if !(count1 >= MIN_GALLOP || count2 >= MIN_GALLOP) { break; } 
+                if !(count1 >= MIN_GALLOP || count2 >= MIN_GALLOP) {
+                    break;
+                } 
             }
             
             if breakOuter { break; }
@@ -748,7 +757,8 @@ impl<T: Ord> &MergeState<T> {
 // Moves elements to from dest to from
 // Unsafe as it makes the from parameter invalid between s2 and s2+len
 #[inline(always)]
-unsafe fn moveVec<T>(dest: &[mut T], s1: uint, from: &[const T], s2: uint, len: uint) {   
+unsafe fn moveVec<T>(dest: &[mut T], s1: uint, 
+                    from: &[const T], s2: uint, len: uint) {   
     assert s1+len <= dest.len() && s2+len <= from.len();
 
     do vec::as_mut_buf(dest) |p, _len| {
diff --git a/src/libstd/test.rs b/src/libstd/test.rs
index 51c0ad385ce..faa22ae0967 100644
--- a/src/libstd/test.rs
+++ b/src/libstd/test.rs
@@ -229,7 +229,7 @@ fn print_failures(st: ConsoleTestState) {
     st.out.write_line(~"\nfailures:");
     let failures = copy st.failures;
     let failures = vec::map(failures, |test| test.name);
-    let failures = sort::merge_sort(|x, y| str::le(*x, *y), failures);
+    let failures = do sort::merge_sort(failures) |x, y| { str::le(*x, *y) };
     for vec::each(failures) |name| {
         st.out.write_line(fmt!("    %s", *name));
     }
@@ -382,7 +382,7 @@ fn filter_tests(opts: &TestOpts,
         pure fn lteq(t1: &TestDesc, t2: &TestDesc) -> bool {
             str::le(t1.name, t2.name)
         }
-        sort::merge_sort(lteq, filtered)
+        sort::merge_sort(filtered, lteq)
     };
 
     move filtered
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index eb4ffb26fb1..a291501ef5f 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -281,7 +281,7 @@ fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
 
     // This is sort of stupid here, converting to a vec of mutables and back
     let v: ~[mut @ast::meta_item] = vec::to_mut(items);
-    std::sort::quick_sort(lteq, v);
+    std::sort::quick_sort(v, lteq);
     vec::from_mut(move v)
 }
 
diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs
index ee9602598d1..342743d8c46 100644
--- a/src/libsyntax/ext/qquote.rs
+++ b/src/libsyntax/ext/qquote.rs
@@ -127,7 +127,7 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
         pure fn by_lo(a: &gather_item, b: &gather_item) -> bool {
             a.lo < b.lo
         }
-        std::sort::merge_sort(by_lo, v)
+        std::sort::merge_sort(v, by_lo)
     };
     return cx;
 }
diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs
index cb304c419e5..c5686153c00 100644
--- a/src/rustc/metadata/cstore.rs
+++ b/src/rustc/metadata/cstore.rs
@@ -166,7 +166,7 @@ fn get_dep_hashes(cstore: cstore) -> ~[~str] {
         vec::push(result, {name: cdata.name, hash: hash});
     };
     pure fn lteq(a: &crate_hash, b: &crate_hash) -> bool {a.name <= b.name}
-    let sorted = std::sort::merge_sort(lteq, result);
+    let sorted = std::sort::merge_sort(result, lteq);
     debug!("sorted:");
     for sorted.each |x| {
         debug!("  hash[%s]: %s", x.name, x.hash);
diff --git a/src/rustc/metadata/encoder.rs b/src/rustc/metadata/encoder.rs
index 3424ea8dd57..8da5fa0aee2 100644
--- a/src/rustc/metadata/encoder.rs
+++ b/src/rustc/metadata/encoder.rs
@@ -1038,7 +1038,7 @@ fn encode_crate_deps(ecx: @encode_ctxt, ebml_w: ebml::Writer,
         pure fn lteq(kv1: &numdep, kv2: &numdep) -> bool {
             kv1.cnum <= kv2.cnum
         }
-        std::sort::quick_sort(lteq, deps);
+        std::sort::quick_sort(deps, lteq);
 
         // Sanity-check the crate numbers
         let mut expected_cnum = 1;
diff --git a/src/rustdoc/sort_pass.rs b/src/rustdoc/sort_pass.rs
index 497c076d3ab..da3cf239538 100644
--- a/src/rustdoc/sort_pass.rs
+++ b/src/rustdoc/sort_pass.rs
@@ -36,7 +36,7 @@ fn fold_mod(
 ) -> doc::ModDoc {
     let doc = fold::default_any_fold_mod(fold, doc);
     doc::ModDoc_({
-        items: sort::merge_sort(fold.ctxt, doc.items),
+        items: sort::merge_sort(doc.items, fold.ctxt),
         .. *doc
     })
 }