diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-03-17 18:10:21 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2023-03-17 18:10:21 +0000 |
| commit | c2ccdfa198be20d49b1ab55cb64855a4c9d33bfb (patch) | |
| tree | 54e6a225492578a67fd4b5a9dffbf65ecd2d46ad | |
| parent | 0d53565b60c54bb3f88ec711e87d45a87502de73 (diff) | |
| download | rust-c2ccdfa198be20d49b1ab55cb64855a4c9d33bfb.tar.gz rust-c2ccdfa198be20d49b1ab55cb64855a4c9d33bfb.zip | |
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.
| -rw-r--r-- | library/core/src/slice/iter.rs | 2 | ||||
| -rw-r--r-- | library/core/src/slice/mod.rs | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 68c7c5f23c9..88b84bd1352 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -132,7 +132,7 @@ iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, { 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)) } }} diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index d319b2bc37f..57b6e0ce4bb 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3822,7 +3822,7 @@ impl<T> [T] { 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. |
