From 9cac4ccc90c135082911c59fa366a88f234c4ecb Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Thu, 8 Aug 2013 22:07:21 +0200 Subject: [PATCH] std::vec: Use iterator::order functions for Eq, Ord, TotalOrd, TotalEq --- src/libstd/vec.rs | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 36201dc5e82..87c2a4f9e0a 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -564,17 +564,19 @@ pub mod traits { use super::Vector; use clone::Clone; - use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Equal, Equiv}; + use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Equiv}; + use iterator::order; use ops::Add; - use option::{Some, None}; impl<'self,T:Eq> Eq for &'self [T] { fn eq(&self, other: & &'self [T]) -> bool { self.len() == other.len() && - self.iter().zip(other.iter()).all(|(s,o)| *s == *o) + order::eq(self.iter(), other.iter()) + } + fn ne(&self, other: & &'self [T]) -> bool { + self.len() != other.len() != + order::ne(self.iter(), other.iter()) } - #[inline] - fn ne(&self, other: & &'self [T]) -> bool { !self.eq(other) } } impl Eq for ~[T] { @@ -594,7 +596,7 @@ pub mod traits { impl<'self,T:TotalEq> TotalEq for &'self [T] { fn equals(&self, other: & &'self [T]) -> bool { self.len() == other.len() && - self.iter().zip(other.iter()).all(|(s,o)| s.equals(o)) + order::equals(self.iter(), other.iter()) } } @@ -625,13 +627,7 @@ pub mod traits { impl<'self,T:TotalOrd> TotalOrd for &'self [T] { fn cmp(&self, other: & &'self [T]) -> Ordering { - for (s,o) in self.iter().zip(other.iter()) { - match s.cmp(o) { - Equal => {}, - non_eq => { return non_eq; } - } - } - self.len().cmp(&other.len()) + order::cmp(self.iter(), other.iter()) } } @@ -645,23 +641,25 @@ pub mod traits { fn cmp(&self, other: &@[T]) -> Ordering { self.as_slice().cmp(&other.as_slice()) } } - impl<'self,T:Ord> Ord for &'self [T] { + impl<'self, T: Eq + Ord> Ord for &'self [T] { fn lt(&self, other: & &'self [T]) -> bool { - for (s,o) in self.iter().zip(other.iter()) { - if *s < *o { return true; } - if *s > *o { return false; } - } - self.len() < other.len() + order::lt(self.iter(), other.iter()) } #[inline] - fn le(&self, other: & &'self [T]) -> bool { !(*other < *self) } + fn le(&self, other: & &'self [T]) -> bool { + order::le(self.iter(), other.iter()) + } #[inline] - fn ge(&self, other: & &'self [T]) -> bool { !(*self < *other) } + fn ge(&self, other: & &'self [T]) -> bool { + order::ge(self.iter(), other.iter()) + } #[inline] - fn gt(&self, other: & &'self [T]) -> bool { *other < *self } + fn gt(&self, other: & &'self [T]) -> bool { + order::gt(self.iter(), other.iter()) + } } - impl Ord for ~[T] { + impl Ord for ~[T] { #[inline] fn lt(&self, other: &~[T]) -> bool { self.as_slice() < other.as_slice() } #[inline] @@ -672,7 +670,7 @@ pub mod traits { fn gt(&self, other: &~[T]) -> bool { self.as_slice() > other.as_slice() } } - impl Ord for @[T] { + impl Ord for @[T] { #[inline] fn lt(&self, other: &@[T]) -> bool { self.as_slice() < other.as_slice() } #[inline]