mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 06:31:09 +00:00
Cleanup our sort usage (#6754)
This commit is contained in:
@@ -64,7 +64,7 @@ where
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addresses.sort_unstable_by(|a, b| a.as_ref().cmp(b.as_ref()));
|
addresses.sort_by(|a, b| a.as_ref().cmp(b.as_ref()));
|
||||||
self.cache.insert(id, addresses);
|
self.cache.insert(id, addresses);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ where
|
|||||||
.collect::<Vec<Addr>>();
|
.collect::<Vec<Addr>>();
|
||||||
|
|
||||||
addresses.dedup();
|
addresses.dedup();
|
||||||
addresses.sort_unstable_by(|a, b| a.as_ref().cmp(b.as_ref()));
|
addresses.sort_by(|a, b| a.as_ref().cmp(b.as_ref()));
|
||||||
|
|
||||||
addresses
|
addresses
|
||||||
.choose_multiple(&mut rng, MAX_NUM_AUTHORITY_CONN)
|
.choose_multiple(&mut rng, MAX_NUM_AUTHORITY_CONN)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ impl RegisteredProtocol {
|
|||||||
id: protocol,
|
id: protocol,
|
||||||
supported_versions: {
|
supported_versions: {
|
||||||
let mut tmp = versions.to_vec();
|
let mut tmp = versions.to_vec();
|
||||||
tmp.sort_unstable_by(|a, b| b.cmp(&a));
|
tmp.sort_by(|a, b| b.cmp(&a));
|
||||||
tmp
|
tmp
|
||||||
},
|
},
|
||||||
handshake_message,
|
handshake_message,
|
||||||
|
|||||||
@@ -893,7 +893,7 @@ impl<T: Trait<I>, I: Instance> ChangeMembers<T::AccountId> for Module<T, I> {
|
|||||||
}
|
}
|
||||||
// remove accounts from all current voting in motions.
|
// remove accounts from all current voting in motions.
|
||||||
let mut outgoing = outgoing.to_vec();
|
let mut outgoing = outgoing.to_vec();
|
||||||
outgoing.sort_unstable();
|
outgoing.sort();
|
||||||
for h in Self::proposals().into_iter() {
|
for h in Self::proposals().into_iter() {
|
||||||
<Voting<T, I>>::mutate(h, |v|
|
<Voting<T, I>>::mutate(h, |v|
|
||||||
if let Some(mut votes) = v.take() {
|
if let Some(mut votes) = v.take() {
|
||||||
|
|||||||
@@ -1211,7 +1211,7 @@ where
|
|||||||
/// the order of items is not preserved.
|
/// the order of items is not preserved.
|
||||||
fn has_duplicates<T: PartialEq + AsRef<[u8]>>(items: &mut Vec<T>) -> bool {
|
fn has_duplicates<T: PartialEq + AsRef<[u8]>>(items: &mut Vec<T>) -> bool {
|
||||||
// Sort the vector
|
// Sort the vector
|
||||||
items.sort_unstable_by(|a, b| {
|
items.sort_by(|a, b| {
|
||||||
Ord::cmp(a.as_ref(), b.as_ref())
|
Ord::cmp(a.as_ref(), b.as_ref())
|
||||||
});
|
});
|
||||||
// And then find any two consecutive equal elements.
|
// And then find any two consecutive equal elements.
|
||||||
|
|||||||
@@ -2889,7 +2889,7 @@ impl<T: Trait> Module<T> {
|
|||||||
let mut exposure_clipped = exposure;
|
let mut exposure_clipped = exposure;
|
||||||
let clipped_max_len = T::MaxNominatorRewardedPerValidator::get() as usize;
|
let clipped_max_len = T::MaxNominatorRewardedPerValidator::get() as usize;
|
||||||
if exposure_clipped.others.len() > clipped_max_len {
|
if exposure_clipped.others.len() > clipped_max_len {
|
||||||
exposure_clipped.others.sort_unstable_by(|a, b| a.value.cmp(&b.value).reverse());
|
exposure_clipped.others.sort_by(|a, b| a.value.cmp(&b.value).reverse());
|
||||||
exposure_clipped.others.truncate(clipped_max_len);
|
exposure_clipped.others.truncate(clipped_max_len);
|
||||||
}
|
}
|
||||||
<ErasStakersClipped<T>>::insert(¤t_era, &stash, exposure_clipped);
|
<ErasStakersClipped<T>>::insert(¤t_era, &stash, exposure_clipped);
|
||||||
|
|||||||
@@ -1238,7 +1238,7 @@ pub trait ChangeMembers<AccountId: Clone + Ord> {
|
|||||||
///
|
///
|
||||||
/// This resets any previous value of prime.
|
/// This resets any previous value of prime.
|
||||||
fn change_members(incoming: &[AccountId], outgoing: &[AccountId], mut new: Vec<AccountId>) {
|
fn change_members(incoming: &[AccountId], outgoing: &[AccountId], mut new: Vec<AccountId>) {
|
||||||
new.sort_unstable();
|
new.sort();
|
||||||
Self::change_members_sorted(incoming, outgoing, &new[..]);
|
Self::change_members_sorted(incoming, outgoing, &new[..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.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(
|
let (versions, old_names) = renames.into_iter().fold(
|
||||||
(Vec::new(), Vec::new()),
|
(Vec::new(), Vec::new()),
|
||||||
|(mut versions, mut old_names), (version, old_name)| {
|
|(mut versions, mut old_names), (version, old_name)| {
|
||||||
|
|||||||
@@ -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
|
// 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.
|
// 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)>>();
|
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 {
|
if needs_bump {
|
||||||
// must increase the values a bit. Bump from the min element. Index of minimum is now zero
|
// 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.
|
// 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())
|
Ok(output_with_idx.into_iter().map(|(_, t)| t).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -749,7 +749,7 @@ fn do_balancing<AccountId>(
|
|||||||
e.1 = 0;
|
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() }
|
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;
|
e.1 = 0.0;
|
||||||
});
|
});
|
||||||
|
|
||||||
elected_edges.sort_unstable_by(|x, y|
|
elected_edges.sort_by(|x, y|
|
||||||
support_map.get(&x.0)
|
support_map.get(&x.0)
|
||||||
.and_then(|x| support_map.get(&y.0).and_then(|y| x.total.partial_cmp(&y.total)))
|
.and_then(|x| support_map.get(&y.0).and_then(|y| x.total.partial_cmp(&y.total)))
|
||||||
.unwrap_or(sp_std::cmp::Ordering::Equal)
|
.unwrap_or(sp_std::cmp::Ordering::Equal)
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ fn prepare_extrinsics_input_inner<'a, B, H, Number>(
|
|||||||
extrinsics.extend(
|
extrinsics.extend(
|
||||||
v.extrinsics().cloned()
|
v.extrinsics().cloned()
|
||||||
);
|
);
|
||||||
extrinsics.sort_unstable();
|
extrinsics.sort();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -566,7 +566,7 @@ mod tests {
|
|||||||
count: 1000,
|
count: 1000,
|
||||||
};
|
};
|
||||||
let mut d = st.make();
|
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();
|
let dr = d.iter().map(|v| (&v.0[..], &v.1[..])).collect();
|
||||||
check_equivalent::<Layout>(&dr);
|
check_equivalent::<Layout>(&dr);
|
||||||
check_iteration::<Layout>(&dr);
|
check_iteration::<Layout>(&dr);
|
||||||
|
|||||||
Reference in New Issue
Block a user