Switch impls of is_sorted_by between slices and slice iters

This makes a bit more sense — iter impl converts to slice first, while
slice impl used to create iter, doing unnecessary conversions.
This commit is contained in:
Maybe Waffle 2023-03-17 18:10:21 +00:00
parent 0d53565b60
commit c2ccdfa198
2 changed files with 2 additions and 2 deletions

View File

@ -132,7 +132,7 @@ iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, {
Self: Sized, Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>, F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
{ {
self.as_slice().array_windows().all(|[a, b]| compare(&a, &b).map_or(false, Ordering::is_le)) self.as_slice().is_sorted_by(|a, b| compare(&a, &b))
} }
}} }}

View File

@ -3822,7 +3822,7 @@ impl<T> [T] {
where where
F: FnMut(&'a T, &'a T) -> Option<Ordering>, F: FnMut(&'a T, &'a T) -> Option<Ordering>,
{ {
self.iter().is_sorted_by(|a, b| compare(*a, *b)) self.array_windows().all(|[a, b]| compare(a, b).map_or(false, Ordering::is_le))
} }
/// Checks if the elements of this slice are sorted using the given key extraction function. /// Checks if the elements of this slice are sorted using the given key extraction function.