From 5e616dbd2189844044e039436b7ed16b44f6595a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 20 Feb 2015 20:32:55 +0300 Subject: Tweaks to equality comparisons for slices/arrays/vectors --- src/libcore/array.rs | 51 ++++++++------------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) (limited to 'src/libcore/array.rs') diff --git a/src/libcore/array.rs b/src/libcore/array.rs index afb5d95c9f8..a24c181b909 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -19,8 +19,7 @@ use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use fmt; use hash::{Hash, self}; use iter::IntoIterator; -use marker::Copy; -use ops::Deref; +use marker::{Copy, Sized}; use option::Option; use slice::{Iter, IterMut, SliceExt}; @@ -76,47 +75,13 @@ macro_rules! array_impls { } } - #[stable(feature = "rust1", since = "1.0.0")] - impl PartialEq<[B; $N]> for [A; $N] where A: PartialEq { - #[inline] - fn eq(&self, other: &[B; $N]) -> bool { - &self[..] == &other[..] - } - #[inline] - fn ne(&self, other: &[B; $N]) -> bool { - &self[..] != &other[..] - } - } - - #[stable(feature = "rust1", since = "1.0.0")] - impl<'a, A, B, Rhs> PartialEq for [A; $N] where - A: PartialEq, - Rhs: Deref, - { - #[inline(always)] - fn eq(&self, other: &Rhs) -> bool { - PartialEq::eq(&self[..], &**other) - } - #[inline(always)] - fn ne(&self, other: &Rhs) -> bool { - PartialEq::ne(&self[..], &**other) - } - } - - #[stable(feature = "rust1", since = "1.0.0")] - impl<'a, A, B, Lhs> PartialEq<[B; $N]> for Lhs where - A: PartialEq, - Lhs: Deref - { - #[inline(always)] - fn eq(&self, other: &[B; $N]) -> bool { - PartialEq::eq(&**self, &other[..]) - } - #[inline(always)] - fn ne(&self, other: &[B; $N]) -> bool { - PartialEq::ne(&**self, &other[..]) - } - } + // NOTE: some less important impls are omitted to reduce code bloat + __impl_slice_eq1! { [A; $N], [B; $N] } + __impl_slice_eq2! { [A; $N], [B] } + __impl_slice_eq2! { [A; $N], &'b [B] } + __impl_slice_eq2! { [A; $N], &'b mut [B] } + // __impl_slice_eq2! { [A; $N], &'b [B; $N] } + // __impl_slice_eq2! { [A; $N], &'b mut [B; $N] } #[stable(feature = "rust1", since = "1.0.0")] impl Eq for [T; $N] { } -- cgit 1.4.1-3-g733a5