Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace range with an external iterator #8216

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2386,9 +2386,8 @@ foreach e in v.iter() {
An example of a for loop over a series of integers:

~~~~
# use std::uint;
# fn bar(b:uint) { }
for uint::range(0, 256) |i| {
foreach i in range(0u, 256) {
bar(i);
}
~~~~
Expand Down
12 changes: 4 additions & 8 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ should interleave the output in vaguely random order.
~~~
# use std::io::print;
# use std::task::spawn;
# use std::int;

for int::range(0, 20) |child_task_number| {
foreach child_task_number in range(0, 20) {
do spawn {
print(fmt!("I am child number %d\n", child_task_number));
}
Expand Down Expand Up @@ -237,12 +236,11 @@ Instead we can use a `SharedChan`, a type that allows a single
~~~
# use std::task::spawn;
# use std::comm::{stream, SharedChan};
# use std::uint;

let (port, chan) = stream();
let chan = SharedChan::new(chan);

for uint::range(0, 3) |init_val| {
foreach init_val in range(0u, 3) {
// Create a new channel handle to distribute to the child task
let child_chan = chan.clone();
do spawn {
Expand Down Expand Up @@ -314,10 +312,9 @@ Here is another example showing how futures allow you to background computations
be distributed on the available cores.
~~~
# use std::vec;
# use std::uint;
fn partial_sum(start: uint) -> f64 {
let mut local_sum = 0f64;
for uint::range(start*100000, (start+1)*100000) |num| {
foreach num in range(start*100000, (start+1)*100000) {
local_sum += (num as f64 + 1.0).pow(&-2.0);
}
local_sum
Expand Down Expand Up @@ -349,7 +346,6 @@ Here is a small example showing how to use Arcs. We wish to run concurrently sev
a single large vector of floats. Each task needs the full vector to perform its duty.
~~~
# use std::vec;
# use std::uint;
# use std::rand;
use extra::arc::Arc;

Expand All @@ -363,7 +359,7 @@ fn main() {

let numbers_arc = Arc::new(numbers);

for uint::range(1,10) |num| {
foreach num in range(1u, 10) {
let (port, chan) = stream();
chan.send(numbers_arc.clone());

Expand Down
3 changes: 1 addition & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use util::logv;
use std::io;
use std::os;
use std::str;
use std::uint;
use std::vec;

use extra::test::MetricMap;
Expand Down Expand Up @@ -414,7 +413,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
}
}

for uint::range(0u, found_flags.len()) |i| {
foreach i in range(0u, found_flags.len()) {
if !found_flags[i] {
let ee = &expected_errors[i];
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",
Expand Down
5 changes: 2 additions & 3 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ mod tests {
use std::cell::Cell;
use std::comm;
use std::task;
use std::uint;

#[test]
fn manually_share_arc() {
Expand Down Expand Up @@ -851,7 +850,7 @@ mod tests {
*state = 31337;
// FIXME: #7372: hits type inference bug with iterators
// send to other readers
for uint::range(0, reader_convos.len()) |i| {
foreach i in range(0u, reader_convos.len()) {
match reader_convos[i] {
(ref rc, _) => rc.send(()),
}
Expand All @@ -861,7 +860,7 @@ mod tests {
do (&read_mode).read |state| {
// FIXME: #7372: hits type inference bug with iterators
// complete handshake with other readers
for uint::range(0, reader_convos.len()) |i| {
foreach i in range(0u, reader_convos.len()) {
match reader_convos[i] {
(_, ref rp) => rp.recv(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl Arena {
#[test]
fn test_arena_destructors() {
let arena = Arena();
for uint::range(0, 10) |i| {
foreach i in range(0u, 10) {
// Arena allocate something with drop glue to make sure it
// doesn't leak.
do arena.alloc { @i };
Expand All @@ -293,7 +293,7 @@ fn test_arena_destructors() {
fn test_arena_destructors_fail() {
let arena = Arena();
// Put some stuff in the arena.
for uint::range(0, 10) |i| {
foreach i in range(0u, 10) {
// Arena allocate something with drop glue to make sure it
// doesn't leak.
do arena.alloc { @i };
Expand Down
17 changes: 8 additions & 9 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::ops;
use std::uint;
use std::vec;


#[deriving(Clone)]
struct SmallBitv {
/// only the lowest nbits of this value are used. the rest is undefined.
Expand Down Expand Up @@ -146,7 +145,7 @@ impl BigBitv {
let len = b.storage.len();
assert_eq!(self.storage.len(), len);
let mut changed = false;
for uint::range(0, len) |i| {
foreach i in range(0, len) {
let mask = big_mask(nbits, i);
let w0 = self.storage[i] & mask;
let w1 = b.storage[i] & mask;
Expand All @@ -161,7 +160,7 @@ impl BigBitv {

#[inline]
pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool {
uint::range(0, self.storage.len(), |i| op(&mut self.storage[i]))
range(0u, self.storage.len()).advance(|i| op(&mut self.storage[i]))
}

#[inline]
Expand Down Expand Up @@ -511,7 +510,7 @@ impl Bitv {
}

pub fn ones(&self, f: &fn(uint) -> bool) -> bool {
uint::range(0, self.nbits, |i| !self.get(i) || f(i))
range(0u, self.nbits).advance(|i| !self.get(i) || f(i))
}

}
Expand Down Expand Up @@ -542,7 +541,7 @@ pub fn from_bools(bools: &[bool]) -> Bitv {
*/
pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv {
let mut bitv = Bitv::new(len, false);
for uint::range(0, len) |i| {
foreach i in range(0u, len) {
bitv.set(i, f(i));
}
bitv
Expand All @@ -559,7 +558,7 @@ fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool {
if bits == 0 {
return true;
}
for uint::range(0, uint::bits) |i| {
foreach i in range(0u, uint::bits) {
if bits & (1 << i) != 0 {
if !f(base + i) {
return false;
Expand Down Expand Up @@ -674,7 +673,7 @@ impl BitvSet {
fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
fn nbits(mut w: uint) -> uint {
let mut bits = 0;
for uint::range(0, uint::bits) |_| {
foreach _ in range(0u, uint::bits) {
if w == 0 {
break;
}
Expand Down Expand Up @@ -1283,12 +1282,12 @@ mod tests {
#[test]
fn test_equal_sneaky_big() {
let mut a = bitv::Bitv::new(100, false);
for uint::range(0, 100) |i| {
foreach i in range(0u, 100) {
a.set(i, true);
}

let mut b = bitv::Bitv::new(100, true);
for uint::range(0, 100) |i| {
foreach i in range(0u, 100) {
b.set(i, true);
}

Expand Down
11 changes: 5 additions & 6 deletions src/libextra/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ pub trait Deque<T> : Mutable {

#[cfg(test)]
mod bench {

use std::container::MutableMap;
use std::{vec,rand,uint};
use std::{vec, rand};
use std::rand::RngUtil;
use test::BenchHarness;

Expand All @@ -54,7 +53,7 @@ mod bench {
let mut rng = rand::XorShiftRng::new();

map.clear();
for uint::range(0,n) |_i| {
foreach _ in range(0, n) {
map.insert(rng.gen::<uint>() % n, 1);
}

Expand All @@ -71,7 +70,7 @@ mod bench {
bh: &mut BenchHarness) {
// setup
map.clear();
for uint::range(0, n) |i| {
foreach i in range(0u, n) {
map.insert(i*2, 1);
}

Expand Down Expand Up @@ -109,7 +108,7 @@ mod bench {
map: &mut M,
bh: &mut BenchHarness) {
// setup
for uint::range(0, n) |i| {
foreach i in range(0u, n) {
map.insert(i, 1);
}

Expand All @@ -120,4 +119,4 @@ mod bench {
i = (i + 1) % n;
}
}
}
}
15 changes: 6 additions & 9 deletions src/libextra/crypto/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


use std::uint;

use digest::Digest;

// BitCounter is a specialized structure intended simply for counting the
Expand Down Expand Up @@ -169,7 +166,7 @@ impl Engine512 {
((x << 45) | (x >> 19)) ^ ((x << 3) | (x >> 61)) ^ (x >> 6)
}

for uint::range(16, 80) |t| {
foreach t in range(16u, 80) {
self.W[t] = sigma1(self.W[t - 2]) + self.W[t - 7] + sigma0(self.W[t - 15]) +
self.W[t - 16];
}
Expand All @@ -184,7 +181,7 @@ impl Engine512 {
let mut h = self.H7;

let mut t = 0;
for uint::range(0, 10) |_| {
foreach _ in range(0u, 10) {
h += sum1(e) + ch(e, f, g) + K64[t] + self.W[t];
d += h;
h += sum0(a) + maj(a, b, c);
Expand Down Expand Up @@ -254,7 +251,7 @@ impl Engine512 {

// add length
if (self.W_idx > 14) {
for uint::range(self.W_idx, 16) |_| {
foreach _ in range(self.W_idx, 16) {
self.process_word(0);
}
}
Expand Down Expand Up @@ -452,7 +449,7 @@ impl Engine256 {
((x >> 17) | (x << 15)) ^ ((x >> 19) | (x << 13)) ^ (x >> 10)
}

for uint::range(16, 64) |t| {
foreach t in range(16u, 64) {
self.W[t] = sigma1(self.W[t - 2]) + self.W[t - 7] + sigma0(self.W[t - 15]) +
self.W[t - 16];
}
Expand All @@ -467,7 +464,7 @@ impl Engine256 {
let mut h = self.H7;

let mut t = 0;
for uint::range(0, 8) |_| {
foreach _ in range(0u, 8) {
h += sum1(e) + ch(e, f, g) + K32[t] + self.W[t];
d += h;
h += sum0(a) + maj(a, b, c);
Expand Down Expand Up @@ -536,7 +533,7 @@ impl Engine256 {

// add length
if (self.W_idx > 14) {
for uint::range(self.W_idx, 16) |_| {
foreach _ in range(self.W_idx, 16) {
self.process_word(0);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ pub fn check_links<T>(list: &DList<T>) {
mod tests {
use super::*;
use std::rand;
use std::int;
use extra::test;

#[test]
Expand Down Expand Up @@ -944,7 +943,7 @@ mod tests {
fn fuzz_test(sz: int) {
let mut m = DList::new::<int>();
let mut v = ~[];
for int::range(0i, sz) |i| {
foreach i in range(0, sz) {
check_links(&m);
let r: u8 = rand::random();
match r % 6 {
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/fileinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ mod test {
input.next_file(); // skip the rest of 1

// read all lines from 1 (but don't read any from 2),
for uint::range(1, 4) |i| {
foreach i in range(1u, 4) {
assert_eq!(input.read_line(), fmt!("1 %u", i));
}
// 1 is finished, but 2 hasn't been started yet, so this will
Expand Down
Loading