diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-03-27 14:15:24 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-03-27 14:17:16 -0400 |
| commit | 91cb6687a8869fa14aef8d978fb13e330c711cd3 (patch) | |
| tree | 9f3390c3e3f094c6aa54be1678e595f330e51a20 /src | |
| parent | b93393e907eddab513fa2be541af4356b8203282 (diff) | |
| download | rust-91cb6687a8869fa14aef8d978fb13e330c711cd3.tar.gz rust-91cb6687a8869fa14aef8d978fb13e330c711cd3.zip | |
cmp: rm TotalOrd impl code duplication
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/cmp.rs | 75 |
1 files changed, 22 insertions, 53 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 7c45ecae632..bc5b4b7f148 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -45,62 +45,31 @@ pub trait TotalOrd { fn cmp(&self, other: &Self) -> Ordering; } -#[inline(always)] -fn icmp<T: Ord>(a: &T, b: &T) -> Ordering { - if *a < *b { Less } - else if *a > *b { Greater } - else { Equal } -} - -impl TotalOrd for u8 { - #[inline(always)] - fn cmp(&self, other: &u8) -> Ordering { icmp(self, other) } -} - -impl TotalOrd for u16 { - #[inline(always)] - fn cmp(&self, other: &u16) -> Ordering { icmp(self, other) } -} - -impl TotalOrd for u32 { - #[inline(always)] - fn cmp(&self, other: &u32) -> Ordering { icmp(self, other) } -} - -impl TotalOrd for u64 { - #[inline(always)] - fn cmp(&self, other: &u64) -> Ordering { icmp(self, other) } -} - -impl TotalOrd for i8 { - #[inline(always)] - fn cmp(&self, other: &i8) -> Ordering { icmp(self, other) } -} - -impl TotalOrd for i16 { - #[inline(always)] - fn cmp(&self, other: &i16) -> Ordering { icmp(self, other) } -} - -impl TotalOrd for i32 { - #[inline(always)] - fn cmp(&self, other: &i32) -> Ordering { icmp(self, other) } -} +macro_rules! totalord_impl( + ($t:ty) => { + impl TotalOrd for $t { + #[inline(always)] + fn cmp(&self, other: &$t) -> Ordering { + if *self < *other { Less } + else if *self > *other { Greater } + else { Equal } + } + } + } +) -impl TotalOrd for i64 { - #[inline(always)] - fn cmp(&self, other: &i64) -> Ordering { icmp(self, other) } -} +totalord_impl!(u8) +totalord_impl!(u16) +totalord_impl!(u32) +totalord_impl!(u64) -impl TotalOrd for int { - #[inline(always)] - fn cmp(&self, other: &int) -> Ordering { icmp(self, other) } -} +totalord_impl!(i8) +totalord_impl!(i16) +totalord_impl!(i32) +totalord_impl!(i64) -impl TotalOrd for uint { - #[inline(always)] - fn cmp(&self, other: &uint) -> Ordering { icmp(self, other) } -} +totalord_impl!(int) +totalord_impl!(uint) /** * Trait for values that can be compared for a sort-order. |
