diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 58f081b25e3e5..cb08765208c62 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -815,8 +815,6 @@ impl cmp::PartialEq for BitvSet { } return true; } - - fn ne(&self, other: &BitvSet) -> bool { !self.eq(other) } } impl fmt::Show for BitvSet { diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index ce4195789fab6..168d2b179e30e 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -371,10 +371,11 @@ fn raw_index(lo: uint, len: uint, index: uint) -> uint { impl PartialEq for RingBuf { fn eq(&self, other: &RingBuf) -> bool { self.nelts == other.nelts && - self.iter().zip(other.iter()).all(|(a, b)| a.eq(b)) + self.iter().zip(other.iter()).all(|(a, b)| a == b) } fn ne(&self, other: &RingBuf) -> bool { - !self.eq(other) + self.nelts != other.nelts || + self.iter().zip(other.iter()).any(|(a, b)| a != b) } } diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index def1c353bc132..2107210b9a44f 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -52,6 +52,10 @@ impl PartialEq for TreeMap { self.len() == other.len() && self.iter().zip(other.iter()).all(|(a, b)| a == b) } + fn ne(&self, other: &TreeMap) -> bool { + self.len() != other.len() || + self.iter().zip(other.iter()).any(|(a, b)| a != b) + } } // Lexicographical comparison @@ -559,6 +563,8 @@ pub struct TreeSet { impl PartialEq for TreeSet { #[inline] fn eq(&self, other: &TreeSet) -> bool { self.map == other.map } + #[inline] + fn ne(&self, other: &TreeSet) -> bool { self.map != other.map } } impl PartialOrd for TreeSet { diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index eef133181e129..31cd1ee98a09f 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -199,9 +199,10 @@ impl Clone for Cell { } impl PartialEq for Cell { - fn eq(&self, other: &Cell) -> bool { - self.get() == other.get() - } + #[inline] + fn eq(&self, other: &Cell) -> bool { self.get() == other.get() } + #[inline] + fn ne(&self, other: &Cell) -> bool { self.get() != other.get() } } /// A mutable memory location with dynamically checked borrow rules diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index b2776b78b1ce3..a80d59a37ffb8 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -404,11 +404,9 @@ impl RawPtr for *mut T { #[cfg(not(test))] impl PartialEq for *T { #[inline] - fn eq(&self, other: &*T) -> bool { - *self == *other - } + fn eq(&self, other: &*T) -> bool { *self == *other } #[inline] - fn ne(&self, other: &*T) -> bool { !self.eq(other) } + fn ne(&self, other: &*T) -> bool { *self != *other } } #[cfg(not(test))] @@ -417,11 +415,9 @@ impl Eq for *T {} #[cfg(not(test))] impl PartialEq for *mut T { #[inline] - fn eq(&self, other: &*mut T) -> bool { - *self == *other - } + fn eq(&self, other: &*mut T) -> bool { *self == *other } #[inline] - fn ne(&self, other: &*mut T) -> bool { !self.eq(other) } + fn ne(&self, other: &*mut T) -> bool { *self != *other } } #[cfg(not(test))] diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 4dea1fd75a4bf..e613c6d4c2acf 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -270,7 +270,7 @@ pub mod traits { #[inline] fn eq(&self, other: &~[T]) -> bool { self.as_slice() == *other } #[inline] - fn ne(&self, other: &~[T]) -> bool { !self.eq(other) } + fn ne(&self, other: &~[T]) -> bool { self.as_slice() != *other } } impl<'a,T:Eq> Eq for &'a [T] {} diff --git a/src/libstd/collections/hashmap.rs b/src/libstd/collections/hashmap.rs index 571c579470441..31de1b6aa6a0a 100644 --- a/src/libstd/collections/hashmap.rs +++ b/src/libstd/collections/hashmap.rs @@ -1420,6 +1420,17 @@ impl, V: PartialEq, S, H: Hasher> PartialEq for HashMap) -> bool { + if self.len() != other.len() { return true; } + + self.iter() + .any(|(key, value)| { + match other.find(key) { + None => true, + Some(v) => *value != *v + } + }) + } } impl, V: Eq, S, H: Hasher> Eq for HashMap {} @@ -1495,10 +1506,13 @@ pub struct HashSet { } impl, S, H: Hasher> PartialEq for HashSet { + #[inline] fn eq(&self, other: &HashSet) -> bool { - if self.len() != other.len() { return false; } - - self.iter().all(|key| other.contains(key)) + self.map == other.map + } + #[inline] + fn ne(&self, other: &HashSet) -> bool { + self.map != other.map } } diff --git a/src/libstd/collections/lru_cache.rs b/src/libstd/collections/lru_cache.rs index a12b00f34dc4a..a5f2fdf30091e 100644 --- a/src/libstd/collections/lru_cache.rs +++ b/src/libstd/collections/lru_cache.rs @@ -73,9 +73,10 @@ impl> Hash for KeyRef { } impl PartialEq for KeyRef { - fn eq(&self, other: &KeyRef) -> bool { - unsafe{ (*self.k).eq(&*other.k) } - } + #[inline] + fn eq(&self, other: &KeyRef) -> bool { unsafe { (&*self.k) == (&*other.k) } } + #[inline] + fn ne(&self, other: &KeyRef) -> bool { unsafe { (&*self.k) != (&*other.k) } } } impl Eq for KeyRef {}