Skip to content

Commit 67729b4

Browse files
committed
Compare pairs with slice::windows
1 parent ccc027e commit 67729b4

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/libcore/iter/iterator.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2655,7 +2655,10 @@ pub trait Iterator {
26552655
};
26562656

26572657
while let Some(curr) = self.next() {
2658-
if compare(&last, &curr).map(|o| o == Ordering::Greater).unwrap_or(true) {
2658+
if compare(&last, &curr)
2659+
.map(|o| o == Ordering::Greater)
2660+
.unwrap_or(true)
2661+
{
26592662
return false;
26602663
}
26612664
last = curr;

src/libcore/slice/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2293,13 +2293,11 @@ impl<T> [T] {
22932293
where
22942294
F: FnMut(&T, &T) -> Option<Ordering>
22952295
{
2296-
let len = self.len();
2297-
if len <= 1 {
2298-
return true;
2299-
}
2300-
2301-
for i in 1..len {
2302-
if compare(&self[i - 1], &self[i]).map(|o| o == Ordering::Greater).unwrap_or(true) {
2296+
for pair in self.windows(2) {
2297+
if compare(&pair[0], &pair[1])
2298+
.map(|o| o == Ordering::Greater)
2299+
.unwrap_or(true)
2300+
{
23032301
return false;
23042302
}
23052303
}

0 commit comments

Comments
 (0)