Cleanup our sort usage (#6754)

This commit is contained in:
Gavin Wood
2020-07-29 14:00:51 +02:00
committed by GitHub
parent 1ab7719314
commit 6bfbb7c6f1
12 changed files with 16 additions and 16 deletions
@@ -384,7 +384,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
renames.push((version, prefix_function_with_trait(&trait_name, &old_name)));
}
renames.sort_unstable_by(|l, r| r.cmp(l));
renames.sort_by(|l, r| r.cmp(l));
let (versions, old_names) = renames.into_iter().fold(
(Vec::new(), Vec::new()),
|(mut versions, mut old_names), (version, old_name)| {
+2 -2
View File
@@ -180,7 +180,7 @@ pub fn normalize<T>(input: &[T], targeted_sum: T) -> Result<Vec<T>, &'static str
// sort output once based on diff. This will require more data transfer and saving original
// index, but we sort only twice instead: once now and once at the very end.
let mut output_with_idx = input.iter().cloned().enumerate().collect::<Vec<(usize, T)>>();
output_with_idx.sort_unstable_by_key(|x| x.1);
output_with_idx.sort_by_key(|x| x.1);
if needs_bump {
// must increase the values a bit. Bump from the min element. Index of minimum is now zero
@@ -262,7 +262,7 @@ pub fn normalize<T>(input: &[T], targeted_sum: T) -> Result<Vec<T>, &'static str
);
// sort again based on the original index.
output_with_idx.sort_unstable_by_key(|x| x.0);
output_with_idx.sort_by_key(|x| x.0);
Ok(output_with_idx.into_iter().map(|(_, t)| t).collect())
}
@@ -749,7 +749,7 @@ fn do_balancing<AccountId>(
e.1 = 0;
});
elected_edges.sort_unstable_by_key(|e|
elected_edges.sort_by_key(|e|
if let Some(e) = support_map.get(&e.0) { e.total } else { Zero::zero() }
);
@@ -264,7 +264,7 @@ pub(crate) fn do_equalize_float<A>(
e.1 = 0.0;
});
elected_edges.sort_unstable_by(|x, y|
elected_edges.sort_by(|x, y|
support_map.get(&x.0)
.and_then(|x| support_map.get(&y.0).and_then(|y| x.total.partial_cmp(&y.total)))
.unwrap_or(sp_std::cmp::Ordering::Equal)
@@ -174,7 +174,7 @@ fn prepare_extrinsics_input_inner<'a, B, H, Number>(
extrinsics.extend(
v.extrinsics().cloned()
);
extrinsics.sort_unstable();
extrinsics.sort();
},
}
+1 -1
View File
@@ -566,7 +566,7 @@ mod tests {
count: 1000,
};
let mut d = st.make();
d.sort_unstable_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
d.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
let dr = d.iter().map(|v| (&v.0[..], &v.1[..])).collect();
check_equivalent::<Layout>(&dr);
check_iteration::<Layout>(&dr);