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 @@ fn is_sorted_by<F>(self, mut compare: F) -> bool
Self: Sized,
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 @@ pub fn is_sorted_by<'a, F>(&'a self, mut compare: F) -> bool
where
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.