Skip to content

Commit 91cb668

Browse files
committed
cmp: rm TotalOrd impl code duplication
1 parent b93393e commit 91cb668

File tree

1 file changed

+22
-53
lines changed

1 file changed

+22
-53
lines changed

src/libcore/cmp.rs

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -45,62 +45,31 @@ pub trait TotalOrd {
4545
fn cmp(&self, other: &Self) -> Ordering;
4646
}
4747

48-
#[inline(always)]
49-
fn icmp<T: Ord>(a: &T, b: &T) -> Ordering {
50-
if *a < *b { Less }
51-
else if *a > *b { Greater }
52-
else { Equal }
53-
}
54-
55-
impl TotalOrd for u8 {
56-
#[inline(always)]
57-
fn cmp(&self, other: &u8) -> Ordering { icmp(self, other) }
58-
}
59-
60-
impl TotalOrd for u16 {
61-
#[inline(always)]
62-
fn cmp(&self, other: &u16) -> Ordering { icmp(self, other) }
63-
}
64-
65-
impl TotalOrd for u32 {
66-
#[inline(always)]
67-
fn cmp(&self, other: &u32) -> Ordering { icmp(self, other) }
68-
}
69-
70-
impl TotalOrd for u64 {
71-
#[inline(always)]
72-
fn cmp(&self, other: &u64) -> Ordering { icmp(self, other) }
73-
}
74-
75-
impl TotalOrd for i8 {
76-
#[inline(always)]
77-
fn cmp(&self, other: &i8) -> Ordering { icmp(self, other) }
78-
}
79-
80-
impl TotalOrd for i16 {
81-
#[inline(always)]
82-
fn cmp(&self, other: &i16) -> Ordering { icmp(self, other) }
83-
}
84-
85-
impl TotalOrd for i32 {
86-
#[inline(always)]
87-
fn cmp(&self, other: &i32) -> Ordering { icmp(self, other) }
88-
}
48+
macro_rules! totalord_impl(
49+
($t:ty) => {
50+
impl TotalOrd for $t {
51+
#[inline(always)]
52+
fn cmp(&self, other: &$t) -> Ordering {
53+
if *self < *other { Less }
54+
else if *self > *other { Greater }
55+
else { Equal }
56+
}
57+
}
58+
}
59+
)
8960

90-
impl TotalOrd for i64 {
91-
#[inline(always)]
92-
fn cmp(&self, other: &i64) -> Ordering { icmp(self, other) }
93-
}
61+
totalord_impl!(u8)
62+
totalord_impl!(u16)
63+
totalord_impl!(u32)
64+
totalord_impl!(u64)
9465

95-
impl TotalOrd for int {
96-
#[inline(always)]
97-
fn cmp(&self, other: &int) -> Ordering { icmp(self, other) }
98-
}
66+
totalord_impl!(i8)
67+
totalord_impl!(i16)
68+
totalord_impl!(i32)
69+
totalord_impl!(i64)
9970

100-
impl TotalOrd for uint {
101-
#[inline(always)]
102-
fn cmp(&self, other: &uint) -> Ordering { icmp(self, other) }
103-
}
71+
totalord_impl!(int)
72+
totalord_impl!(uint)
10473

10574
/**
10675
* Trait for values that can be compared for a sort-order.

0 commit comments

Comments
 (0)