Skip to content

Commit 6a93b85

Browse files
authored
dominoes, saddle-points: sort_unstable instead of sort (#1002)
clippy: warning: Use sort_unstable instead of sort note: `#[warn(clippy::stable_sort_primitive)]` on by default help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive When sorting primitive values (integers, bools, chars, as well as arrays, slices, and tuples of such items), it is better to use an unstable sort than a stable sort. Using a stable sort consumes more memory and cpu cycles. Because values which compare equal are identical, preserving their relative order (the guarantee that a stable sort provides) means nothing, while the extra costs still apply.
1 parent 90354d3 commit 6a93b85

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

exercises/dominoes/tests/dominoes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ fn check(input: &[Domino]) -> CheckResult {
3535
.iter()
3636
.map(|&d| normalize(d))
3737
.collect::<Vec<Domino>>();
38-
output_sorted.sort();
38+
output_sorted.sort_unstable();
3939
let mut input_sorted = input.iter().map(|&d| normalize(d)).collect::<Vec<Domino>>();
40-
input_sorted.sort();
40+
input_sorted.sort_unstable();
4141
if input_sorted != output_sorted {
4242
return DominoMismatch(output);
4343
}

exercises/saddle-points/tests/saddle-points.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use saddle_points::find_saddle_points;
33
// We don't care about order
44
fn find_sorted_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> {
55
let mut result = saddle_points::find_saddle_points(input);
6-
result.sort();
6+
result.sort_unstable();
77
result
88
}
99

0 commit comments

Comments
 (0)