diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cmp.rs | 21 | ||||
| -rw-r--r-- | src/libcore/str.rs | 6 | ||||
| -rw-r--r-- | src/libcore/tuple.rs | 1 |
3 files changed, 26 insertions, 2 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index f96575aaf41..bd4832b6faf 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -116,6 +116,19 @@ totalord_impl!(i64) totalord_impl!(int) totalord_impl!(uint) +pub fn cmp2<A:TotalOrd,B:TotalOrd>( + a1: &A, b1: &B, + a2: &A, b2: &B) -> Ordering +{ + //! Compares (a1, b1) against (a2, b2), where the a values are more significant. + + match a1.cmp(a2) { + Less => Less, + Greater => Greater, + Equal => b1.cmp(b2) + } +} + /** * Trait for values that can be compared for a sort-order. * @@ -194,6 +207,14 @@ mod test { } #[test] + fn test_cmp2() { + assert_eq!(cmp2(1, 2, 3, 4), Less); + assert_eq!(cmp2(3, 2, 3, 4), Less); + assert_eq!(cmp2(5, 2, 3, 4), Greater); + assert_eq!(cmp2(5, 5, 5, 4), Greater); + } + + #[test] fn test_int_totaleq() { assert!(5.equals(&5)); assert!(!2.equals(&17)); diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f1605309fb4..8d15d6afbda 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -301,7 +301,11 @@ pub fn slice_shift_char<'a>(s: &'a str) -> (char, &'a str) { /// Prepend a char to a string pub fn unshift_char(s: &mut ~str, ch: char) { - *s = from_char(ch) + *s; + // This could be more efficient. + let mut new_str = ~""; + new_str.push_char(ch); + new_str.push_str(*s); + *s = new_str; } /** diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index 35b8496f6c5..8234129e254 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -161,7 +161,6 @@ impl<A:Ord> Ord for (A,) { fn gt(&self, other: &(A,)) -> bool { other.lt(&(*self)) } } - #[cfg(notest)] impl<A:Eq,B:Eq> Eq for (A, B) { #[inline(always)] |
