@@ -2435,145 +2435,67 @@ pub trait Iterator {
2435
2435
/// Determines if the elements of this `Iterator` are unequal to those of
2436
2436
/// another.
2437
2437
#[ 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
2439
2439
I : IntoIterator ,
2440
2440
Self :: Item : PartialEq < I :: Item > ,
2441
2441
Self : Sized ,
2442
2442
{
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)
2458
2444
}
2459
2445
2460
2446
/// Determines if the elements of this `Iterator` are lexicographically
2461
2447
/// less than those of another.
2462
2448
#[ 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
2464
2450
I : IntoIterator ,
2465
2451
Self :: Item : PartialOrd < I :: Item > ,
2466
2452
Self : Sized ,
2467
2453
{
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 ,
2487
2457
}
2488
2458
}
2489
2459
2490
2460
/// Determines if the elements of this `Iterator` are lexicographically
2491
2461
/// less or equal to those of another.
2492
2462
#[ 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
2494
2464
I : IntoIterator ,
2495
2465
Self :: Item : PartialOrd < I :: Item > ,
2496
2466
Self : Sized ,
2497
2467
{
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 ,
2517
2471
}
2518
2472
}
2519
2473
2520
2474
/// Determines if the elements of this `Iterator` are lexicographically
2521
2475
/// greater than those of another.
2522
2476
#[ 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
2524
2478
I : IntoIterator ,
2525
2479
Self :: Item : PartialOrd < I :: Item > ,
2526
2480
Self : Sized ,
2527
2481
{
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 ,
2547
2485
}
2548
2486
}
2549
2487
2550
2488
/// Determines if the elements of this `Iterator` are lexicographically
2551
2489
/// greater than or equal to those of another.
2552
2490
#[ 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
2554
2492
I : IntoIterator ,
2555
2493
Self :: Item : PartialOrd < I :: Item > ,
2556
2494
Self : Sized ,
2557
2495
{
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 ,
2577
2499
}
2578
2500
}
2579
2501
0 commit comments