@@ -564,17 +564,19 @@ pub mod traits {
564
564
use super :: Vector ;
565
565
566
566
use clone:: Clone ;
567
- use cmp:: { Eq , Ord , TotalEq , TotalOrd , Ordering , Equal , Equiv } ;
567
+ use cmp:: { Eq , Ord , TotalEq , TotalOrd , Ordering , Equiv } ;
568
+ use iterator:: order;
568
569
use ops:: Add ;
569
- use option:: { Some , None } ;
570
570
571
571
impl < ' self , T : Eq > Eq for & ' self [ T ] {
572
572
fn eq ( & self , other : & & ' self [ T ] ) -> bool {
573
573
self . len ( ) == other. len ( ) &&
574
- self . iter ( ) . zip ( other. iter ( ) ) . all ( |( s, o) | * s == * o)
574
+ order:: eq ( self . iter ( ) , other. iter ( ) )
575
+ }
576
+ fn ne ( & self , other : & & ' self [ T ] ) -> bool {
577
+ self . len ( ) != other. len ( ) !=
578
+ order:: ne ( self . iter ( ) , other. iter ( ) )
575
579
}
576
- #[ inline]
577
- fn ne ( & self , other : & & ' self [ T ] ) -> bool { !self . eq ( other) }
578
580
}
579
581
580
582
impl < T : Eq > Eq for ~[ T ] {
@@ -594,7 +596,7 @@ pub mod traits {
594
596
impl < ' self , T : TotalEq > TotalEq for & ' self [ T ] {
595
597
fn equals ( & self , other : & & ' self [ T ] ) -> bool {
596
598
self . len ( ) == other. len ( ) &&
597
- self . iter ( ) . zip ( other. iter ( ) ) . all ( | ( s , o ) | s . equals ( o ) )
599
+ order :: equals ( self . iter ( ) , other. iter ( ) )
598
600
}
599
601
}
600
602
@@ -625,13 +627,7 @@ pub mod traits {
625
627
626
628
impl < ' self , T : TotalOrd > TotalOrd for & ' self [ T ] {
627
629
fn cmp ( & self , other : & & ' self [ T ] ) -> Ordering {
628
- for ( s, o) in self . iter ( ) . zip ( other. iter ( ) ) {
629
- match s. cmp ( o) {
630
- Equal => { } ,
631
- non_eq => { return non_eq; }
632
- }
633
- }
634
- self . len ( ) . cmp ( & other. len ( ) )
630
+ order:: cmp ( self . iter ( ) , other. iter ( ) )
635
631
}
636
632
}
637
633
@@ -645,23 +641,25 @@ pub mod traits {
645
641
fn cmp ( & self , other : & @[ T ] ) -> Ordering { self . as_slice ( ) . cmp ( & other. as_slice ( ) ) }
646
642
}
647
643
648
- impl < ' self , T : Ord > Ord for & ' self [ T ] {
644
+ impl < ' self , T : Eq + Ord > Ord for & ' self [ T ] {
649
645
fn lt ( & self , other : & & ' self [ T ] ) -> bool {
650
- for ( s, o) in self . iter ( ) . zip ( other. iter ( ) ) {
651
- if * s < * o { return true ; }
652
- if * s > * o { return false ; }
653
- }
654
- self . len ( ) < other. len ( )
646
+ order:: lt ( self . iter ( ) , other. iter ( ) )
655
647
}
656
648
#[ inline]
657
- fn le ( & self , other : & & ' self [ T ] ) -> bool { !( * other < * self ) }
649
+ fn le ( & self , other : & & ' self [ T ] ) -> bool {
650
+ order:: le ( self . iter ( ) , other. iter ( ) )
651
+ }
658
652
#[ inline]
659
- fn ge ( & self , other : & & ' self [ T ] ) -> bool { !( * self < * other) }
653
+ fn ge ( & self , other : & & ' self [ T ] ) -> bool {
654
+ order:: ge ( self . iter ( ) , other. iter ( ) )
655
+ }
660
656
#[ inline]
661
- fn gt ( & self , other : & & ' self [ T ] ) -> bool { * other < * self }
657
+ fn gt ( & self , other : & & ' self [ T ] ) -> bool {
658
+ order:: gt ( self . iter ( ) , other. iter ( ) )
659
+ }
662
660
}
663
661
664
- impl < T : Ord > Ord for ~[ T ] {
662
+ impl < T : Eq + Ord > Ord for ~[ T ] {
665
663
#[ inline]
666
664
fn lt ( & self , other : & ~[ T ] ) -> bool { self . as_slice ( ) < other. as_slice ( ) }
667
665
#[ inline]
@@ -672,7 +670,7 @@ pub mod traits {
672
670
fn gt ( & self , other : & ~[ T ] ) -> bool { self . as_slice ( ) > other. as_slice ( ) }
673
671
}
674
672
675
- impl < T : Ord > Ord for @[ T ] {
673
+ impl < T : Eq + Ord > Ord for @[ T ] {
676
674
#[ inline]
677
675
fn lt ( & self , other : & @[ T ] ) -> bool { self . as_slice ( ) < other. as_slice ( ) }
678
676
#[ inline]
0 commit comments