Skip to content

Commit 1b1e4ca

Browse files
committed
std::vec: add a sugary .sort() method for plain Ord sorting.
This moves the custom sorting to `.sort_by`.
1 parent 48fedcb commit 1b1e4ca

File tree

16 files changed

+91
-27
lines changed

16 files changed

+91
-27
lines changed

src/libextra/glob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl Iterator<Path> for GlobIterator {
148148
fn list_dir_sorted(path: &Path) -> ~[Path] {
149149
match io::result(|| fs::readdir(path)) {
150150
Ok(mut children) => {
151-
children.sort(|p1, p2| p2.filename() <= p1.filename());
151+
children.sort_by(|p1, p2| p2.filename() <= p1.filename());
152152
children
153153
}
154154
Err(..) => ~[]

src/libextra/priority_queue.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ mod tests {
231231
fn test_top_and_pop() {
232232
let data = ~[2u, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1];
233233
let mut sorted = data.clone();
234+
<<<<<<< HEAD
234235
sorted.sort(|x, y| x.le(y));
236+
=======
237+
sorted.sort();
238+
>>>>>>> 9ceda35... std::vec: add a sugary .sort() method for plain Ord sorting.
235239
let mut heap = PriorityQueue::from_vec(data);
236240
while !heap.is_empty() {
237241
assert_eq!(heap.top(), sorted.last());
@@ -314,8 +318,8 @@ mod tests {
314318
fn check_to_vec(mut data: ~[int]) {
315319
let heap = PriorityQueue::from_vec(data.clone());
316320
let mut v = heap.clone().to_vec();
317-
v.sort(|x, y| x.le(y));
318-
data.sort(|x, y| x.le(y));
321+
v.sort();
322+
data.sort();
319323

320324
assert_eq!(v, data);
321325
assert_eq!(heap.to_sorted_vec(), data);

src/libextra/stats.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,13 @@ impl<'a> Stats for &'a [f64] {
239239

240240
fn percentile(self, pct: f64) -> f64 {
241241
let mut tmp = self.to_owned();
242-
tmp.sort(|a,b| a <= b);
242+
tmp.sort();
243243
percentile_of_sorted(tmp, pct)
244244
}
245245

246246
fn quartiles(self) -> (f64,f64,f64) {
247247
let mut tmp = self.to_owned();
248-
tmp.sort(|a,b| a <= b);
248+
tmp.sort();
249249
let a = percentile_of_sorted(tmp, 25.0);
250250
let b = percentile_of_sorted(tmp, 50.0);
251251
let c = percentile_of_sorted(tmp, 75.0);
@@ -290,7 +290,7 @@ fn percentile_of_sorted(sorted_samples: &[f64],
290290
/// See: http://en.wikipedia.org/wiki/Winsorising
291291
pub fn winsorize(samples: &mut [f64], pct: f64) {
292292
let mut tmp = samples.to_owned();
293-
tmp.sort(|a,b| a <= b);
293+
tmp.sort();
294294
let lo = percentile_of_sorted(tmp, pct);
295295
let hi = percentile_of_sorted(tmp, 100.0-pct);
296296
for samp in samples.mut_iter() {

src/libextra/test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use std::to_str::ToStr;
3737
use std::f64;
3838
use std::os;
3939

40-
4140
// The name of a test. By convention this follows the rules for rust
4241
// paths; i.e. it should be a series of identifiers separated by double
4342
// colons. This way if some test runner wants to arrange the tests
@@ -487,7 +486,7 @@ impl<T: Writer> ConsoleTestState<T> {
487486
for f in self.failures.iter() {
488487
failures.push(f.name.to_str());
489488
}
490-
failures.sort(|a,b| a <= b);
489+
failures.sort();
491490
for name in failures.iter() {
492491
self.write_plain(format!(" {}\n", name.to_str()));
493492
}
@@ -841,7 +840,7 @@ pub fn filter_tests(
841840
fn lteq(t1: &TestDescAndFn, t2: &TestDescAndFn) -> bool {
842841
t1.desc.name.to_str() <= t2.desc.name.to_str()
843842
}
844-
filtered.sort(lteq);
843+
filtered.sort_by(lteq);
845844

846845
// Shard the remaining tests, if sharding requested.
847846
match opts.test_shard {

src/librustc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Available lint options:
162162
let mut lint_dict = lint_dict.move_iter()
163163
.map(|(k, v)| (v, k))
164164
.collect::<~[(lint::LintSpec, &'static str)]>();
165-
lint_dict.sort(|a,b| a <= b);
165+
lint_dict.sort();
166166

167167
let mut max_key = 0;
168168
for &(_, name) in lint_dict.iter() {

src/librustc/metadata/cstore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub fn get_dep_hashes(cstore: &CStore) -> ~[@str] {
191191
});
192192
}
193193

194-
result.sort(|a, b| (a.name, a.vers, a.hash) <= (b.name, b.vers, b.hash));
194+
result.sort();
195195

196196
debug!("sorted:");
197197
for x in result.iter() {

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ fn encode_crate_deps(ecx: &EncodeContext,
15311531
});
15321532

15331533
// Sort by cnum
1534-
deps.sort(|kv1, kv2| kv1.cnum <= kv2.cnum);
1534+
deps.sort_by(|kv1, kv2| kv1.cnum <= kv2.cnum);
15351535

15361536
// Sanity-check the crate numbers
15371537
let mut expected_cnum = 1;

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn missing_ctor(cx: &MatchCheckCtxt,
464464

465465
// Sort them by length such that for patterns of the same length,
466466
// those with a destructured slice come first.
467-
vec_pat_lens.sort(|&(len1, slice1), &(len2, slice2)| {
467+
vec_pat_lens.sort_by(|&(len1, slice1), &(len2, slice2)| {
468468
if len1 == len2 {
469469
slice1 > slice2
470470
} else {

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3163,7 +3163,7 @@ pub fn trans_crate(sess: session::Session,
31633163
println!("n_closures: {}", ccx.stats.n_closures);
31643164
println("fn stats:");
31653165

3166-
ccx.stats.fn_stats.sort(|&(_, _, insns_a), &(_, _, insns_b)| insns_a >= insns_b);
3166+
ccx.stats.fn_stats.sort_by(|&(_, _, insns_a), &(_, _, insns_b)| insns_a >= insns_b);
31673167

31683168
for tuple in ccx.stats.fn_stats.iter() {
31693169
match *tuple {

src/librustdoc/html/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ fn item_module(w: &mut Writer, cx: &Context,
935935
}
936936

937937
debug!("{:?}", indices);
938-
indices.sort(|&i1, &i2| le(&items[i1], &items[i2], i1, i2));
938+
indices.sort_by(|&i1, &i2| le(&items[i1], &items[i2], i1, i2));
939939

940940
debug!("{:?}", indices);
941941
let mut curty = "";

0 commit comments

Comments
 (0)