diff options
| author | bors <bors@rust-lang.org> | 2013-09-19 00:31:05 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-19 00:31:05 -0700 |
| commit | a7cf7b7b0b3392bc3219e2bea44a0a18283aae50 (patch) | |
| tree | 8967276fc1f070a5537e713320a2b4401312de9c /src/libstd | |
| parent | 3c0013134cecbe9592f02ed5c6a94c06effb19d4 (diff) | |
| parent | 47576313695170013cfe07d57e81c2e879a14c14 (diff) | |
| download | rust-a7cf7b7b0b3392bc3219e2bea44a0a18283aae50.tar.gz rust-a7cf7b7b0b3392bc3219e2bea44a0a18283aae50.zip | |
auto merge of #9291 : jzelinskie/rust/remove-cond, r=alexcrichton
This is my first contribution, so please point out anything that I may have missed.
I consulted IRC and settled on `match () { ... }` for most of the replacements.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/char.rs | 24 | ||||
| -rw-r--r-- | src/libstd/num/f32.rs | 36 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 36 | ||||
| -rw-r--r-- | src/libstd/num/uint_macros.rs | 10 |
4 files changed, 53 insertions, 53 deletions
diff --git a/src/libstd/char.rs b/src/libstd/char.rs index 911d883f88a..431fc27a202 100644 --- a/src/libstd/char.rs +++ b/src/libstd/char.rs @@ -281,11 +281,11 @@ pub fn escape_unicode(c: char, f: &fn(char)) { // avoid calling str::to_str_radix because we don't really need to allocate // here. f('\\'); - let pad = cond!( - (c <= '\xff') { f('x'); 2 } - (c <= '\uffff') { f('u'); 4 } - _ { f('U'); 8 } - ); + let pad = match () { + _ if c <= '\xff' => { f('x'); 2 } + _ if c <= '\uffff' => { f('u'); 4 } + _ => { f('U'); 8 } + }; for offset in range_step::<i32>(4 * (pad - 1), -1, -4) { unsafe { match ((c as i32) >> offset) & 0xf { @@ -329,13 +329,13 @@ pub fn len_utf8_bytes(c: char) -> uint { static MAX_FOUR_B: uint = 2097152u; let code = c as uint; - cond!( - (code < MAX_ONE_B) { 1u } - (code < MAX_TWO_B) { 2u } - (code < MAX_THREE_B) { 3u } - (code < MAX_FOUR_B) { 4u } - _ { fail!("invalid character!") } - ) + match () { + _ if code < MAX_ONE_B => 1u, + _ if code < MAX_TWO_B => 2u, + _ if code < MAX_THREE_B => 3u, + _ if code < MAX_FOUR_B => 4u, + _ => fail!("invalid character!"), + } } impl ToStr for char { diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 1bb488d0278..2787e028645 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -206,35 +206,35 @@ impl Orderable for f32 { /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn min(&self, other: &f32) -> f32 { - cond!( - (self.is_NaN()) { *self } - (other.is_NaN()) { *other } - (*self < *other) { *self } - _ { *other } - ) + match () { + _ if self.is_NaN() => *self, + _ if other.is_NaN() => *other, + _ if *self < *other => *self, + _ => *other, + } } /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn max(&self, other: &f32) -> f32 { - cond!( - (self.is_NaN()) { *self } - (other.is_NaN()) { *other } - (*self > *other) { *self } - _ { *other } - ) + match () { + _ if self.is_NaN() => *self, + _ if other.is_NaN() => *other, + _ if *self > *other => *self, + _ => *other, + } } /// Returns the number constrained within the range `mn <= self <= mx`. /// If any of the numbers are `NaN` then `NaN` is returned. #[inline] fn clamp(&self, mn: &f32, mx: &f32) -> f32 { - cond!( - (self.is_NaN()) { *self } - (!(*self <= *mx)) { *mx } - (!(*self >= *mn)) { *mn } - _ { *self } - ) + match () { + _ if self.is_NaN() => *self, + _ if !(*self <= *mx) => *mx, + _ if !(*self >= *mn) => *mn, + _ => *self, + } } } diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 604eac0a0a7..afc22ec212b 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -229,35 +229,35 @@ impl Orderable for f64 { /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn min(&self, other: &f64) -> f64 { - cond!( - (self.is_NaN()) { *self } - (other.is_NaN()) { *other } - (*self < *other) { *self } - _ { *other } - ) + match () { + _ if self.is_NaN() => *self, + _ if other.is_NaN() => *other, + _ if *self < *other => *self, + _ => *other, + } } /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn max(&self, other: &f64) -> f64 { - cond!( - (self.is_NaN()) { *self } - (other.is_NaN()) { *other } - (*self > *other) { *self } - _ { *other } - ) + match () { + _ if self.is_NaN() => *self, + _ if other.is_NaN() => *other, + _ if *self > *other => *self, + _ => *other, + } } /// Returns the number constrained within the range `mn <= self <= mx`. /// If any of the numbers are `NaN` then `NaN` is returned. #[inline] fn clamp(&self, mn: &f64, mx: &f64) -> f64 { - cond!( - (self.is_NaN()) { *self } - (!(*self <= *mx)) { *mx } - (!(*self >= *mn)) { *mn } - _ { *self } - ) + match () { + _ if self.is_NaN() => *self, + _ if !(*self <= *mx) => *mx, + _ if !(*self >= *mn) => *mn, + _ => *self, + } } } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index 0a9c912a6e2..7cd1be7ab74 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -70,11 +70,11 @@ impl Orderable for $T { /// Returns the number constrained within the range `mn <= self <= mx`. #[inline] fn clamp(&self, mn: &$T, mx: &$T) -> $T { - cond!( - (*self > *mx) { *mx } - (*self < *mn) { *mn } - _ { *self } - ) + match () { + _ if (*self > *mx) => *mx, + _ if (*self < *mn) => *mn, + _ => *self, + } } } |
