Skip to content

Commit c2ccdfa

Browse files
committed
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.
1 parent 0d53565 commit c2ccdfa

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/slice/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, {
132132
Self: Sized,
133133
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
134134
{
135-
self.as_slice().array_windows().all(|[a, b]| compare(&a, &b).map_or(false, Ordering::is_le))
135+
self.as_slice().is_sorted_by(|a, b| compare(&a, &b))
136136
}
137137
}}
138138

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3822,7 +3822,7 @@ impl<T> [T] {
38223822
where
38233823
F: FnMut(&'a T, &'a T) -> Option<Ordering>,
38243824
{
3825-
self.iter().is_sorted_by(|a, b| compare(*a, *b))
3825+
self.array_windows().all(|[a, b]| compare(a, b).map_or(false, Ordering::is_le))
38263826
}
38273827

38283828
/// Checks if the elements of this slice are sorted using the given key extraction function.

0 commit comments

Comments
 (0)