Skip to content

Commit

Permalink
perf: reduce TandemSorter size
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Sep 6, 2023
1 parent 1afb31e commit 7949e2f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/util/tandem_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::Ordering;
/// Stores the sorted order for an initial list so that multiple
/// lists can be sorted based on that order.
pub(crate) struct TandemSorter {
indices: Vec<usize>,
indices: Box<[usize]>,
}

impl TandemSorter {
Expand All @@ -13,7 +13,7 @@ impl TandemSorter {
where
T: PartialOrd,
{
let mut indices: Vec<_> = (0..).take(slice.len()).collect();
let mut indices: Box<[usize]> = (0..).take(slice.len()).collect();

let closure =
|&i: &usize, &j: &usize| slice[i].partial_cmp(&slice[j]).unwrap_or(Ordering::Equal);
Expand Down Expand Up @@ -87,11 +87,8 @@ mod tests {
assert_eq!(base, vec![1, 2, 3, 4, 5, 7, 8, 9]);

sorter.toggle_marks();
let mut other = vec!['h', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'];
let mut other = "hello World".chars().collect::<Vec<_>>();
sorter.sort(&mut other);
assert_eq!(
other,
vec!['l', 'o', ' ', 'o', 'W', 'e', 'l', 'h', 'r', 'l', 'd']
);
assert_eq!(other, "lo oWelhrld".chars().collect::<Vec<_>>());
}
}

0 comments on commit 7949e2f

Please sign in to comment.