diff options
| author | Andrea Canciani <ranma42@gmail.com> | 2016-01-21 20:20:22 +0100 |
|---|---|---|
| committer | Andrea Canciani <ranma42@gmail.com> | 2016-01-21 20:49:10 +0100 |
| commit | 2f4622a36fc45cc3ec130b52011a72e5ce2947f9 (patch) | |
| tree | 6ce156ff6d86630ea42fd28349c3db2ae5592d53 /src/libcore | |
| parent | c6ba7fee97e6834f3a72281f88621c10bd562669 (diff) | |
| download | rust-2f4622a36fc45cc3ec130b52011a72e5ce2947f9.tar.gz rust-2f4622a36fc45cc3ec130b52011a72e5ce2947f9.zip | |
Remove `unsafe` code from `core::cmp`
Instead of transmuting, use a match; the compiler has learnt how to optimize it.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cmp.rs | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 3ac4ffb2236..b8bf54628ac 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -19,7 +19,6 @@ use self::Ordering::*; -use mem; use marker::Sized; use option::Option::{self, Some}; @@ -119,10 +118,6 @@ pub enum Ordering { } impl Ordering { - unsafe fn from_i8_unchecked(v: i8) -> Ordering { - mem::transmute(v) - } - /// Reverse the `Ordering`. /// /// * `Less` becomes `Greater`. @@ -155,14 +150,10 @@ impl Ordering { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn reverse(self) -> Ordering { - unsafe { - // this compiles really nicely (to a single instruction); - // an explicit match has a pile of branches and - // comparisons. - // - // NB. it is safe because of the explicit discriminants - // given above. - Ordering::from_i8_unchecked(-(self as i8)) + match self { + Less => Greater, + Equal => Equal, + Greater => Less, } } } |
