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:
parent
0d53565b60
commit
c2ccdfa198
@ -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))
|
||||
}
|
||||
}}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user