]> git.lizzy.rs Git - rust.git/commitdiff
Remove redundant Ord method impls.
authorOGINO Masanori <masanori.ogino@gmail.com>
Thu, 8 Aug 2013 01:03:34 +0000 (10:03 +0900)
committerOGINO Masanori <masanori.ogino@gmail.com>
Fri, 9 Aug 2013 05:28:14 +0000 (14:28 +0900)
Basically, generic containers should not use the default methods since a
type of elements may not guarantees total order. str could use them
since u8's Ord guarantees total order. Floating point numbers are also
broken with the default methods because of NaN. Thanks for @thestinger.

Timespec also guarantees total order AIUI. I'm unsure whether
extra::semver::Identifier does so I left it alone. Proof needed.

Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
src/libextra/time.rs
src/libstd/bool.rs
src/libstd/char.rs
src/libstd/cmp.rs
src/libstd/nil.rs
src/libstd/num/int_macros.rs
src/libstd/num/uint_macros.rs
src/libstd/str.rs

index f6a5fd98234b58aabab5898bdc13b9137c500ee3..cf8ceb463b256cdc7782343d5640f909bcdea694 100644 (file)
@@ -57,9 +57,6 @@ fn lt(&self, other: &Timespec) -> bool {
         self.sec < other.sec ||
             (self.sec == other.sec && self.nsec < other.nsec)
     }
-    fn le(&self, other: &Timespec) -> bool { !other.lt(self) }
-    fn ge(&self, other: &Timespec) -> bool { !self.lt(other) }
-    fn gt(&self, other: &Timespec) -> bool { !self.le(other) }
 }
 
 /**
index eeaea6a2cffa92f2f2e28ffb70c08359ac60d04d..598e808061839f683c0fac6a3d8ec74afb54b4ac 100644 (file)
@@ -284,12 +284,6 @@ fn not(&self) -> bool { !*self }
 impl Ord for bool {
     #[inline]
     fn lt(&self, other: &bool) -> bool { to_bit(*self) < to_bit(*other) }
-    #[inline]
-    fn le(&self, other: &bool) -> bool { to_bit(*self) <= to_bit(*other) }
-    #[inline]
-    fn gt(&self, other: &bool) -> bool { to_bit(*self) > to_bit(*other) }
-    #[inline]
-    fn ge(&self, other: &bool) -> bool { to_bit(*self) >= to_bit(*other) }
 }
 
 #[cfg(not(test))]
index 8505385543213720901ea1fcae0b0b46da83329d..9c55e22b1f833794a0cd70548de8140c757021d8 100644 (file)
@@ -322,12 +322,6 @@ fn ne(&self, other: &char) -> bool { (*self) != (*other) }
 impl Ord for char {
     #[inline]
     fn lt(&self, other: &char) -> bool { *self < *other }
-    #[inline]
-    fn le(&self, other: &char) -> bool { *self <= *other }
-    #[inline]
-    fn gt(&self, other: &char) -> bool { *self > *other }
-    #[inline]
-    fn ge(&self, other: &char) -> bool { *self >= *other }
 }
 
 #[cfg(not(test))]
index b66f89e83415e1b22ad0a575f950f1855057460f..28d45abb6881f0dc8190c96f5a97865273f031f5 100644 (file)
@@ -101,12 +101,6 @@ fn cmp(&self, other: &Ordering) -> Ordering {
 impl Ord for Ordering {
     #[inline]
     fn lt(&self, other: &Ordering) -> bool { (*self as int) < (*other as int) }
-    #[inline]
-    fn le(&self, other: &Ordering) -> bool { (*self as int) <= (*other as int) }
-    #[inline]
-    fn gt(&self, other: &Ordering) -> bool { (*self as int) > (*other as int) }
-    #[inline]
-    fn ge(&self, other: &Ordering) -> bool { (*self as int) >= (*other as int) }
 }
 
 macro_rules! totalord_impl(
@@ -174,8 +168,11 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
 #[lang="ord"]
 pub trait Ord {
     fn lt(&self, other: &Self) -> bool;
+    #[inline]
     fn le(&self, other: &Self) -> bool { !other.lt(self) }
+    #[inline]
     fn gt(&self, other: &Self) -> bool {  other.lt(self) }
+    #[inline]
     fn ge(&self, other: &Self) -> bool { !self.lt(other) }
 }
 
index 81b7662e58168e6b86ea6a759471800a3af9b6e6..3507dc9d2b233543bdf76c6f2cb31f43d2cfd548 100644 (file)
@@ -33,12 +33,6 @@ fn ne(&self, _other: &()) -> bool { false }
 impl Ord for () {
     #[inline]
     fn lt(&self, _other: &()) -> bool { false }
-    #[inline]
-    fn le(&self, _other: &()) -> bool { true }
-    #[inline]
-    fn ge(&self, _other: &()) -> bool { true }
-    #[inline]
-    fn gt(&self, _other: &()) -> bool { false }
 }
 
 #[cfg(not(test))]
index b692bedebfd54f0ed17b39f5fcc99701abec5d32..41da9a6ccbe481a3a559e588a9bc4de5d642ca55 100644 (file)
@@ -130,12 +130,6 @@ impl Num for $T {}
 impl Ord for $T {
     #[inline]
     fn lt(&self, other: &$T) -> bool { return (*self) < (*other); }
-    #[inline]
-    fn le(&self, other: &$T) -> bool { return (*self) <= (*other); }
-    #[inline]
-    fn ge(&self, other: &$T) -> bool { return (*self) >= (*other); }
-    #[inline]
-    fn gt(&self, other: &$T) -> bool { return (*self) > (*other); }
 }
 
 #[cfg(not(test))]
index 29b8f29d87d3f866a37bff576ea9e408be768687..86b5b4ddfc09f4318f5fd94dc2f9ad859014c5ac 100644 (file)
@@ -131,12 +131,6 @@ impl Num for $T {}
 impl Ord for $T {
     #[inline]
     fn lt(&self, other: &$T) -> bool { (*self) < (*other) }
-    #[inline]
-    fn le(&self, other: &$T) -> bool { (*self) <= (*other) }
-    #[inline]
-    fn ge(&self, other: &$T) -> bool { (*self) >= (*other) }
-    #[inline]
-    fn gt(&self, other: &$T) -> bool { (*self) > (*other) }
 }
 
 #[cfg(not(test))]
index fa75916fb8640e10785c53b3e70c6c69aab93a89..430eb8544f6306f73245f885ff4110796a487f96 100644 (file)
@@ -1050,34 +1050,16 @@ fn equals(&self, other: &@str) -> bool {
     impl<'self> Ord for &'self str {
         #[inline]
         fn lt(&self, other: & &'self str) -> bool { self.cmp(other) == Less }
-        #[inline]
-        fn le(&self, other: & &'self str) -> bool { self.cmp(other) != Greater }
-        #[inline]
-        fn ge(&self, other: & &'self str) -> bool { self.cmp(other) != Less }
-        #[inline]
-        fn gt(&self, other: & &'self str) -> bool { self.cmp(other) == Greater }
     }
 
     impl Ord for ~str {
         #[inline]
         fn lt(&self, other: &~str) -> bool { self.cmp(other) == Less }
-        #[inline]
-        fn le(&self, other: &~str) -> bool { self.cmp(other) != Greater }
-        #[inline]
-        fn ge(&self, other: &~str) -> bool { self.cmp(other) != Less }
-        #[inline]
-        fn gt(&self, other: &~str) -> bool { self.cmp(other) == Greater }
     }
 
     impl Ord for @str {
         #[inline]
         fn lt(&self, other: &@str) -> bool { self.cmp(other) == Less }
-        #[inline]
-        fn le(&self, other: &@str) -> bool { self.cmp(other) != Greater }
-        #[inline]
-        fn ge(&self, other: &@str) -> bool { self.cmp(other) != Less }
-        #[inline]
-        fn gt(&self, other: &@str) -> bool { self.cmp(other) == Greater }
     }
 
     impl<'self, S: Str> Equiv<S> for &'self str {