Skip to content

Commit 9cac4cc

Browse files
author
blake2-ppc
committed
std::vec: Use iterator::order functions for Eq, Ord, TotalOrd, TotalEq
1 parent e0b0853 commit 9cac4cc

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/libstd/vec.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -564,17 +564,19 @@ pub mod traits {
564564
use super::Vector;
565565

566566
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;
568569
use ops::Add;
569-
use option::{Some, None};
570570

571571
impl<'self,T:Eq> Eq for &'self [T] {
572572
fn eq(&self, other: & &'self [T]) -> bool {
573573
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())
575579
}
576-
#[inline]
577-
fn ne(&self, other: & &'self [T]) -> bool { !self.eq(other) }
578580
}
579581

580582
impl<T:Eq> Eq for ~[T] {
@@ -594,7 +596,7 @@ pub mod traits {
594596
impl<'self,T:TotalEq> TotalEq for &'self [T] {
595597
fn equals(&self, other: & &'self [T]) -> bool {
596598
self.len() == other.len() &&
597-
self.iter().zip(other.iter()).all(|(s,o)| s.equals(o))
599+
order::equals(self.iter(), other.iter())
598600
}
599601
}
600602

@@ -625,13 +627,7 @@ pub mod traits {
625627

626628
impl<'self,T:TotalOrd> TotalOrd for &'self [T] {
627629
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())
635631
}
636632
}
637633

@@ -645,23 +641,25 @@ pub mod traits {
645641
fn cmp(&self, other: &@[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) }
646642
}
647643

648-
impl<'self,T:Ord> Ord for &'self [T] {
644+
impl<'self, T: Eq + Ord> Ord for &'self [T] {
649645
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())
655647
}
656648
#[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+
}
658652
#[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+
}
660656
#[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+
}
662660
}
663661

664-
impl<T:Ord> Ord for ~[T] {
662+
impl<T: Eq + Ord> Ord for ~[T] {
665663
#[inline]
666664
fn lt(&self, other: &~[T]) -> bool { self.as_slice() < other.as_slice() }
667665
#[inline]
@@ -672,7 +670,7 @@ pub mod traits {
672670
fn gt(&self, other: &~[T]) -> bool { self.as_slice() > other.as_slice() }
673671
}
674672

675-
impl<T:Ord> Ord for @[T] {
673+
impl<T: Eq + Ord> Ord for @[T] {
676674
#[inline]
677675
fn lt(&self, other: &@[T]) -> bool { self.as_slice() < other.as_slice() }
678676
#[inline]

0 commit comments

Comments
 (0)