Skip to content

Commit a10974d

Browse files
committed
Use cond! macro where appropriate
1 parent 8badea4 commit a10974d

File tree

5 files changed

+78
-6
lines changed

5 files changed

+78
-6
lines changed

src/libcore/num/f32.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,27 @@ impl Orderable for f32 {
248248
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
249249
}
250250

251-
/// Returns the number constrained within the range `mn <= self <= mx`.
252-
/// If any of the numbers are `NaN` then `NaN` is returned.
251+
#[cfg(stage0)]
253252
#[inline(always)]
254253
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
255254
if self.is_NaN() { *self }
256255
else if !(*self <= *mx) { *mx }
257256
else if !(*self >= *mn) { *mn }
258257
else { *self }
259258
}
259+
260+
/// Returns the number constrained within the range `mn <= self <= mx`.
261+
/// If any of the numbers are `NaN` then `NaN` is returned.
262+
#[cfg(not(stage0))]
263+
#[inline(always)]
264+
fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
265+
cond!(
266+
(self.is_NaN()) { *self }
267+
(!(*self <= *mx)) { *mx }
268+
(!(*self >= *mn)) { *mn }
269+
_ { *self }
270+
)
271+
}
260272
}
261273

262274
impl Zero for f32 {

src/libcore/num/f64.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,27 @@ impl Orderable for f64 {
270270
if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
271271
}
272272

273-
/// Returns the number constrained within the range `mn <= self <= mx`.
274-
/// If any of the numbers are `NaN` then `NaN` is returned.
273+
#[cfg(stage0)]
275274
#[inline(always)]
276275
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
277276
if self.is_NaN() { *self }
278277
else if !(*self <= *mx) { *mx }
279278
else if !(*self >= *mn) { *mn }
280279
else { *self }
281280
}
281+
282+
/// Returns the number constrained within the range `mn <= self <= mx`.
283+
/// If any of the numbers are `NaN` then `NaN` is returned.
284+
#[cfg(not(stage0))]
285+
#[inline(always)]
286+
fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
287+
cond!(
288+
(self.is_NaN()) { *self }
289+
(!(*self <= *mx)) { *mx }
290+
(!(*self >= *mn)) { *mn }
291+
_ { *self }
292+
)
293+
}
282294
}
283295

284296
impl Zero for f64 {

src/libcore/num/int-template.rs

+12
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,23 @@ impl Orderable for T {
187187
if *self > *other { *self } else { *other }
188188
}
189189

190+
#[cfg(stage0)]
190191
#[inline(always)]
191192
fn clamp(&self, mn: &T, mx: &T) -> T {
192193
if *self > *mx { *mx } else
193194
if *self < *mn { *mn } else { *self }
194195
}
196+
197+
/// Returns the number constrained within the range `mn <= self <= mx`.
198+
#[cfg(not(stage0))]
199+
#[inline(always)]
200+
fn clamp(&self, mn: &T, mx: &T) -> T {
201+
cond!(
202+
(*self > *mx) { *mx }
203+
(*self < *mn) { *mn }
204+
_ { *self }
205+
)
206+
}
195207
}
196208

197209
impl Zero for T {

src/libcore/num/uint-template.rs

+12
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,23 @@ impl Orderable for T {
153153
if *self > *other { *self } else { *other }
154154
}
155155

156+
#[cfg(stage0)]
156157
#[inline(always)]
157158
fn clamp(&self, mn: &T, mx: &T) -> T {
158159
if *self > *mx { *mx } else
159160
if *self < *mn { *mn } else { *self }
160161
}
162+
163+
/// Returns the number constrained within the range `mn <= self <= mx`.
164+
#[cfg(not(stage0))]
165+
#[inline(always)]
166+
fn clamp(&self, mn: &T, mx: &T) -> T {
167+
cond!(
168+
(*self > *mx) { *mx }
169+
(*self < *mn) { *mn }
170+
_ { *self }
171+
)
172+
}
161173
}
162174

163175
impl Zero for T {

src/libcore/unicode.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
pub mod general_category {
1616

17+
#[cfg(stage0)]
1718
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
1819
use cmp::{Equal, Less, Greater};
1920
use vec::bsearch;
@@ -25,6 +26,18 @@ pub mod general_category {
2526
}) != None
2627
}
2728

29+
#[cfg(not(stage0))]
30+
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
31+
use cmp::{Equal, Less, Greater};
32+
use vec::bsearch;
33+
use option::None;
34+
(do bsearch(r) |&(lo,hi)| { cond!(
35+
(lo <= c && c <= hi) { Equal }
36+
(hi < c) { Less }
37+
_ { Greater }
38+
)}) != None
39+
}
40+
2841

2942
static Cc_table : &'static [(char,char)] = &[
3043
('\x00', '\x1f'), ('\x7f', '\x9f')
@@ -1449,8 +1462,7 @@ pub mod general_category {
14491462
}
14501463

14511464
pub mod derived_property {
1452-
1453-
1465+
#[cfg(stage0)]
14541466
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
14551467
use cmp::{Equal, Less, Greater};
14561468
use vec::bsearch;
@@ -1462,6 +1474,18 @@ pub mod derived_property {
14621474
}) != None
14631475
}
14641476

1477+
#[cfg(not(stage0))]
1478+
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
1479+
use cmp::{Equal, Less, Greater};
1480+
use vec::bsearch;
1481+
use option::None;
1482+
(do bsearch(r) |&(lo,hi)| { cond!(
1483+
(lo <= c && c <= hi) { Equal }
1484+
(hi < c) { Less }
1485+
_ { Greater }
1486+
)}) != None
1487+
}
1488+
14651489

14661490
static Alphabetic_table : &'static [(char,char)] = &[
14671491
('\x41', '\x5a'), ('\x61', '\x7a'),

0 commit comments

Comments
 (0)