Skip to content

Cleanup slice sort related closures in core and alloc #101816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<T> [T] {
where
T: Ord,
{
merge_sort(self, |a, b| a.lt(b));
merge_sort(self, T::lt);
}

/// Sorts the slice with a comparator function.
Expand Down
11 changes: 4 additions & 7 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ impl<T> [T] {
where
T: Ord,
{
sort::quicksort(self, |a, b| a.lt(b));
sort::quicksort(self, T::lt);
}

/// Sorts the slice with a comparator function, but might not preserve the order of equal
Expand Down Expand Up @@ -2679,8 +2679,7 @@ impl<T> [T] {
where
T: Ord,
{
let mut f = |a: &T, b: &T| a.lt(b);
sort::partition_at_index(self, index, &mut f)
sort::partition_at_index(self, index, T::lt)
}

/// Reorder the slice with a comparator function such that the element at `index` is at its
Expand Down Expand Up @@ -2731,8 +2730,7 @@ impl<T> [T] {
where
F: FnMut(&T, &T) -> Ordering,
{
let mut f = |a: &T, b: &T| compare(a, b) == Less;
sort::partition_at_index(self, index, &mut f)
sort::partition_at_index(self, index, |a: &T, b: &T| compare(a, b) == Less)
}

/// Reorder the slice with a key extraction function such that the element at `index` is at its
Expand Down Expand Up @@ -2784,8 +2782,7 @@ impl<T> [T] {
F: FnMut(&T) -> K,
K: Ord,
{
let mut g = |a: &T, b: &T| f(a).lt(&f(b));
sort::partition_at_index(self, index, &mut g)
sort::partition_at_index(self, index, |a: &T, b: &T| f(a).lt(&f(b)))
}

/// Moves all consecutive repeated elements to the end of the slice according to the
Expand Down