Skip to content

Commit 079d9b1

Browse files
committed
Forward Iterator::{ne, lt, le, gt, ge} to Iterator::{eq, partial_cmp}
1 parent 070cebd commit 079d9b1

File tree

1 file changed

+18
-96
lines changed

1 file changed

+18
-96
lines changed

src/libcore/iter/traits/iterator.rs

+18-96
Original file line numberDiff line numberDiff line change
@@ -2435,145 +2435,67 @@ pub trait Iterator {
24352435
/// Determines if the elements of this `Iterator` are unequal to those of
24362436
/// another.
24372437
#[stable(feature = "iter_order", since = "1.5.0")]
2438-
fn ne<I>(mut self, other: I) -> bool where
2438+
fn ne<I>(self, other: I) -> bool where
24392439
I: IntoIterator,
24402440
Self::Item: PartialEq<I::Item>,
24412441
Self: Sized,
24422442
{
2443-
let mut other = other.into_iter();
2444-
2445-
loop {
2446-
let x = match self.next() {
2447-
None => return other.next().is_some(),
2448-
Some(val) => val,
2449-
};
2450-
2451-
let y = match other.next() {
2452-
None => return true,
2453-
Some(val) => val,
2454-
};
2455-
2456-
if x != y { return true }
2457-
}
2443+
!self.eq(other)
24582444
}
24592445

24602446
/// Determines if the elements of this `Iterator` are lexicographically
24612447
/// less than those of another.
24622448
#[stable(feature = "iter_order", since = "1.5.0")]
2463-
fn lt<I>(mut self, other: I) -> bool where
2449+
fn lt<I>(self, other: I) -> bool where
24642450
I: IntoIterator,
24652451
Self::Item: PartialOrd<I::Item>,
24662452
Self: Sized,
24672453
{
2468-
let mut other = other.into_iter();
2469-
2470-
loop {
2471-
let x = match self.next() {
2472-
None => return other.next().is_some(),
2473-
Some(val) => val,
2474-
};
2475-
2476-
let y = match other.next() {
2477-
None => return false,
2478-
Some(val) => val,
2479-
};
2480-
2481-
match x.partial_cmp(&y) {
2482-
Some(Ordering::Less) => return true,
2483-
Some(Ordering::Equal) => (),
2484-
Some(Ordering::Greater) => return false,
2485-
None => return false,
2486-
}
2454+
match self.partial_cmp(other) {
2455+
Some(Ordering::Less) => true,
2456+
_ => false,
24872457
}
24882458
}
24892459

24902460
/// Determines if the elements of this `Iterator` are lexicographically
24912461
/// less or equal to those of another.
24922462
#[stable(feature = "iter_order", since = "1.5.0")]
2493-
fn le<I>(mut self, other: I) -> bool where
2463+
fn le<I>(self, other: I) -> bool where
24942464
I: IntoIterator,
24952465
Self::Item: PartialOrd<I::Item>,
24962466
Self: Sized,
24972467
{
2498-
let mut other = other.into_iter();
2499-
2500-
loop {
2501-
let x = match self.next() {
2502-
None => { other.next(); return true; },
2503-
Some(val) => val,
2504-
};
2505-
2506-
let y = match other.next() {
2507-
None => return false,
2508-
Some(val) => val,
2509-
};
2510-
2511-
match x.partial_cmp(&y) {
2512-
Some(Ordering::Less) => return true,
2513-
Some(Ordering::Equal) => (),
2514-
Some(Ordering::Greater) => return false,
2515-
None => return false,
2516-
}
2468+
match self.partial_cmp(other) {
2469+
Some(Ordering::Less) | Some(Ordering::Equal) => true,
2470+
_ => false,
25172471
}
25182472
}
25192473

25202474
/// Determines if the elements of this `Iterator` are lexicographically
25212475
/// greater than those of another.
25222476
#[stable(feature = "iter_order", since = "1.5.0")]
2523-
fn gt<I>(mut self, other: I) -> bool where
2477+
fn gt<I>(self, other: I) -> bool where
25242478
I: IntoIterator,
25252479
Self::Item: PartialOrd<I::Item>,
25262480
Self: Sized,
25272481
{
2528-
let mut other = other.into_iter();
2529-
2530-
loop {
2531-
let x = match self.next() {
2532-
None => { other.next(); return false; },
2533-
Some(val) => val,
2534-
};
2535-
2536-
let y = match other.next() {
2537-
None => return true,
2538-
Some(val) => val,
2539-
};
2540-
2541-
match x.partial_cmp(&y) {
2542-
Some(Ordering::Less) => return false,
2543-
Some(Ordering::Equal) => (),
2544-
Some(Ordering::Greater) => return true,
2545-
None => return false,
2546-
}
2482+
match self.partial_cmp(other) {
2483+
Some(Ordering::Greater) => true,
2484+
_ => false,
25472485
}
25482486
}
25492487

25502488
/// Determines if the elements of this `Iterator` are lexicographically
25512489
/// greater than or equal to those of another.
25522490
#[stable(feature = "iter_order", since = "1.5.0")]
2553-
fn ge<I>(mut self, other: I) -> bool where
2491+
fn ge<I>(self, other: I) -> bool where
25542492
I: IntoIterator,
25552493
Self::Item: PartialOrd<I::Item>,
25562494
Self: Sized,
25572495
{
2558-
let mut other = other.into_iter();
2559-
2560-
loop {
2561-
let x = match self.next() {
2562-
None => return other.next().is_none(),
2563-
Some(val) => val,
2564-
};
2565-
2566-
let y = match other.next() {
2567-
None => return true,
2568-
Some(val) => val,
2569-
};
2570-
2571-
match x.partial_cmp(&y) {
2572-
Some(Ordering::Less) => return false,
2573-
Some(Ordering::Equal) => (),
2574-
Some(Ordering::Greater) => return true,
2575-
None => return false,
2576-
}
2496+
match self.partial_cmp(other) {
2497+
Some(Ordering::Greater) | Some(Ordering::Equal) => true,
2498+
_ => false,
25772499
}
25782500
}
25792501

0 commit comments

Comments
 (0)