about summary refs log tree commit diff
path: root/src/libcore/num/int-template.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-05-10 17:56:02 -0700
committerbors <bors@rust-lang.org>2013-05-10 17:56:02 -0700
commit3e0400fb86170baff30282edcdccff73e243fd6e (patch)
treeec7cc5de5ce7c80845c77fdcbb670cd54c120783 /src/libcore/num/int-template.rs
parentd546493096f35e68cbcd9b5d3d7654e7a9345744 (diff)
parent606bd75586419948f109de313ab37e31397ca7a3 (diff)
downloadrust-3e0400fb86170baff30282edcdccff73e243fd6e.tar.gz
rust-3e0400fb86170baff30282edcdccff73e243fd6e.zip
auto merge of #6223 : alexcrichton/rust/issue-6183, r=pcwalton
Closes #6183.

The first commit changes the compiler's method of treating a `for` loop, and all the remaining commits are just dealing with the fallout.

The biggest fallout was the `IterBytes` trait, although it's really a whole lot nicer now because all of the `iter_bytes_XX` methods are just and-ed together. Sadly there was a huge amount of stuff that's `cfg(stage0)` gated, but whoever lands the next snapshot is going to have a lot of fun deleting all this code!

Diffstat (limited to 'src/libcore/num/int-template.rs')
-rw-r--r--src/libcore/num/int-template.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs
index 9ee5ba4753d..f2bba6a4639 100644
--- a/src/libcore/num/int-template.rs
+++ b/src/libcore/num/int-template.rs
@@ -86,38 +86,63 @@ pub fn gt(x: T, y: T) -> bool { x > y }
 ///
 #[inline(always)]
 /// Iterate over the range [`start`,`start`+`step`..`stop`)
-pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
+pub fn _range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) -> bool {
     let mut i = start;
     if step == 0 {
         fail!(~"range_step called with step == 0");
     } else if step > 0 { // ascending
         while i < stop {
-            if !it(i) { break }
+            if !it(i) { return false; }
             // avoiding overflow. break if i + step > max_value
-            if i > max_value - step { break; }
+            if i > max_value - step { return true; }
             i += step;
         }
     } else { // descending
         while i > stop {
-            if !it(i) { break }
+            if !it(i) { return false; }
             // avoiding underflow. break if i + step < min_value
-            if i < min_value - step { break; }
+            if i < min_value - step { return true; }
             i += step;
         }
     }
+    return true;
+}
+
+#[cfg(stage0)]
+pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) {
+    _range_step(start, stop, step, it);
+}
+#[cfg(not(stage0))]
+pub fn range_step(start: T, stop: T, step: T, it: &fn(T) -> bool) -> bool {
+    _range_step(start, stop, step, it)
 }
 
 #[inline(always)]
+#[cfg(stage0)]
 /// Iterate over the range [`lo`..`hi`)
 pub fn range(lo: T, hi: T, it: &fn(T) -> bool) {
     range_step(lo, hi, 1 as T, it);
 }
 
 #[inline(always)]
+#[cfg(not(stage0))]
+/// Iterate over the range [`lo`..`hi`)
+pub fn range(lo: T, hi: T, it: &fn(T) -> bool) -> bool {
+    range_step(lo, hi, 1 as T, it)
+}
+
+#[inline(always)]
+#[cfg(stage0)]
 /// Iterate over the range [`hi`..`lo`)
 pub fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) {
     range_step(hi, lo, -1 as T, it);
 }
+#[inline(always)]
+#[cfg(not(stage0))]
+/// Iterate over the range [`hi`..`lo`)
+pub fn range_rev(hi: T, lo: T, it: &fn(T) -> bool) -> bool {
+    range_step(hi, lo, -1 as T, it)
+}
 
 /// Computes the bitwise complement
 #[inline(always)]