about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-05-18 15:02:58 +1000
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-05-18 17:29:07 +1000
commita10974da2db2e483f21e337f0c9a8a1e1c4c81ed (patch)
tree8f8bf9bc9ae05e9970ffeb2cd357257ac341e803 /src/libcore
parent8badea49b0291d5ea0979a8edfb1ebb4f01b043d (diff)
downloadrust-a10974da2db2e483f21e337f0c9a8a1e1c4c81ed.tar.gz
rust-a10974da2db2e483f21e337f0c9a8a1e1c4c81ed.zip
Use cond! macro where appropriate
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/num/f32.rs16
-rw-r--r--src/libcore/num/f64.rs16
-rw-r--r--src/libcore/num/int-template.rs12
-rw-r--r--src/libcore/num/uint-template.rs12
-rw-r--r--src/libcore/unicode.rs28
5 files changed, 78 insertions, 6 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs
index 4a3ec3528f2..d580f7aa26c 100644
--- a/src/libcore/num/f32.rs
+++ b/src/libcore/num/f32.rs
@@ -248,8 +248,7 @@ impl Orderable for f32 {
         if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
     }
 
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    /// If any of the numbers are `NaN` then `NaN` is returned.
+    #[cfg(stage0)]
     #[inline(always)]
     fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
         if self.is_NaN() { *self }
@@ -257,6 +256,19 @@ impl Orderable for f32 {
         else if !(*self >= *mn) { *mn }
         else { *self }
     }
+
+    /// Returns the number constrained within the range `mn <= self <= mx`.
+    /// If any of the numbers are `NaN` then `NaN` is returned.
+    #[cfg(not(stage0))]
+    #[inline(always)]
+    fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
+        cond!(
+            (self.is_NaN())   { *self }
+            (!(*self <= *mx)) { *mx   }
+            (!(*self >= *mn)) { *mn   }
+            _                 { *self }
+        )
+    }
 }
 
 impl Zero for f32 {
diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs
index e370f43a003..d140df30c42 100644
--- a/src/libcore/num/f64.rs
+++ b/src/libcore/num/f64.rs
@@ -270,8 +270,7 @@ impl Orderable for f64 {
         if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) }
     }
 
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    /// If any of the numbers are `NaN` then `NaN` is returned.
+    #[cfg(stage0)]
     #[inline(always)]
     fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
         if self.is_NaN() { *self }
@@ -279,6 +278,19 @@ impl Orderable for f64 {
         else if !(*self >= *mn) { *mn }
         else { *self }
     }
+
+    /// Returns the number constrained within the range `mn <= self <= mx`.
+    /// If any of the numbers are `NaN` then `NaN` is returned.
+    #[cfg(not(stage0))]
+    #[inline(always)]
+    fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
+        cond!(
+            (self.is_NaN())   { *self }
+            (!(*self <= *mx)) { *mx   }
+            (!(*self >= *mn)) { *mn   }
+            _                 { *self }
+        )
+    }
 }
 
 impl Zero for f64 {
diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs
index 348f72f9f0a..d0e6174ec63 100644
--- a/src/libcore/num/int-template.rs
+++ b/src/libcore/num/int-template.rs
@@ -187,11 +187,23 @@ impl Orderable for T {
         if *self > *other { *self } else { *other }
     }
 
+    #[cfg(stage0)]
     #[inline(always)]
     fn clamp(&self, mn: &T, mx: &T) -> T {
         if *self > *mx { *mx } else
         if *self < *mn { *mn } else { *self }
     }
+
+    /// Returns the number constrained within the range `mn <= self <= mx`.
+    #[cfg(not(stage0))]
+    #[inline(always)]
+    fn clamp(&self, mn: &T, mx: &T) -> T {
+        cond!(
+            (*self > *mx) { *mx   }
+            (*self < *mn) { *mn   }
+            _             { *self }
+        )
+    }
 }
 
 impl Zero for T {
diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs
index da0815c264b..f3e14094505 100644
--- a/src/libcore/num/uint-template.rs
+++ b/src/libcore/num/uint-template.rs
@@ -153,11 +153,23 @@ impl Orderable for T {
         if *self > *other { *self } else { *other }
     }
 
+    #[cfg(stage0)]
     #[inline(always)]
     fn clamp(&self, mn: &T, mx: &T) -> T {
         if *self > *mx { *mx } else
         if *self < *mn { *mn } else { *self }
     }
+
+    /// Returns the number constrained within the range `mn <= self <= mx`.
+    #[cfg(not(stage0))]
+    #[inline(always)]
+    fn clamp(&self, mn: &T, mx: &T) -> T {
+        cond!(
+            (*self > *mx) { *mx   }
+            (*self < *mn) { *mn   }
+            _             { *self }
+        )
+    }
 }
 
 impl Zero for T {
diff --git a/src/libcore/unicode.rs b/src/libcore/unicode.rs
index d6e2c5eee6a..3b7fdcc85be 100644
--- a/src/libcore/unicode.rs
+++ b/src/libcore/unicode.rs
@@ -14,6 +14,7 @@
 
 pub mod general_category {
 
+    #[cfg(stage0)]
     fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
         use cmp::{Equal, Less, Greater};
         use vec::bsearch;
@@ -25,6 +26,18 @@ pub mod general_category {
         }) != None
     }
 
+    #[cfg(not(stage0))]
+    fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
+        use cmp::{Equal, Less, Greater};
+        use vec::bsearch;
+        use option::None;
+        (do bsearch(r) |&(lo,hi)| { cond!(
+            (lo <= c && c <= hi) { Equal   }
+            (hi < c)             { Less    }
+            _                    { Greater }
+        )}) != None
+    }
+
 
     static Cc_table : &'static [(char,char)] = &[
         ('\x00', '\x1f'), ('\x7f', '\x9f')
@@ -1449,8 +1462,7 @@ pub mod general_category {
 }
 
 pub mod derived_property {
-
-
+    #[cfg(stage0)]
     fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
         use cmp::{Equal, Less, Greater};
         use vec::bsearch;
@@ -1462,6 +1474,18 @@ pub mod derived_property {
         }) != None
     }
 
+    #[cfg(not(stage0))]
+    fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
+        use cmp::{Equal, Less, Greater};
+        use vec::bsearch;
+        use option::None;
+        (do bsearch(r) |&(lo,hi)| { cond!(
+            (lo <= c && c <= hi) { Equal   }
+            (hi < c)             { Less    }
+            _                    { Greater }
+        )}) != None
+    }
+
 
     static Alphabetic_table : &'static [(char,char)] = &[
         ('\x41', '\x5a'), ('\x61', '\x7a'),