Skip to content

Commit 234acad

Browse files
committed
replace range with an external iterator
1 parent 5890fcf commit 234acad

File tree

117 files changed

+336
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+336
-442
lines changed

doc/rust.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2386,9 +2386,8 @@ foreach e in v.iter() {
23862386
An example of a for loop over a series of integers:
23872387

23882388
~~~~
2389-
# use std::uint;
23902389
# fn bar(b:uint) { }
2391-
for uint::range(0, 256) |i| {
2390+
foreach i in range(0u, 256) {
23922391
bar(i);
23932392
}
23942393
~~~~

doc/tutorial-tasks.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ should interleave the output in vaguely random order.
120120
~~~
121121
# use std::io::print;
122122
# use std::task::spawn;
123-
# use std::int;
124123
125-
for int::range(0, 20) |child_task_number| {
124+
foreach child_task_number in range(0, 20) {
126125
do spawn {
127126
print(fmt!("I am child number %d\n", child_task_number));
128127
}
@@ -237,12 +236,11 @@ Instead we can use a `SharedChan`, a type that allows a single
237236
~~~
238237
# use std::task::spawn;
239238
# use std::comm::{stream, SharedChan};
240-
# use std::uint;
241239
242240
let (port, chan) = stream();
243241
let chan = SharedChan::new(chan);
244242
245-
for uint::range(0, 3) |init_val| {
243+
foreach init_val in range(0u, 3) {
246244
// Create a new channel handle to distribute to the child task
247245
let child_chan = chan.clone();
248246
do spawn {
@@ -314,10 +312,9 @@ Here is another example showing how futures allow you to background computations
314312
be distributed on the available cores.
315313
~~~
316314
# use std::vec;
317-
# use std::uint;
318315
fn partial_sum(start: uint) -> f64 {
319316
let mut local_sum = 0f64;
320-
for uint::range(start*100000, (start+1)*100000) |num| {
317+
foreach num in range(start*100000, (start+1)*100000) {
321318
local_sum += (num as f64 + 1.0).pow(&-2.0);
322319
}
323320
local_sum
@@ -349,7 +346,6 @@ Here is a small example showing how to use Arcs. We wish to run concurrently sev
349346
a single large vector of floats. Each task needs the full vector to perform its duty.
350347
~~~
351348
# use std::vec;
352-
# use std::uint;
353349
# use std::rand;
354350
use extra::arc::Arc;
355351
@@ -363,7 +359,7 @@ fn main() {
363359
364360
let numbers_arc = Arc::new(numbers);
365361
366-
for uint::range(1,10) |num| {
362+
foreach num in range(1u, 10) {
367363
let (port, chan) = stream();
368364
chan.send(numbers_arc.clone());
369365

src/compiletest/runtest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use util::logv;
2323
use std::io;
2424
use std::os;
2525
use std::str;
26-
use std::uint;
2726
use std::vec;
2827

2928
use extra::test::MetricMap;
@@ -414,7 +413,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
414413
}
415414
}
416415

417-
for uint::range(0u, found_flags.len()) |i| {
416+
foreach i in range(0u, found_flags.len()) {
418417
if !found_flags[i] {
419418
let ee = &expected_errors[i];
420419
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",

src/libextra/arc.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ mod tests {
566566
use std::cell::Cell;
567567
use std::comm;
568568
use std::task;
569-
use std::uint;
570569
571570
#[test]
572571
fn manually_share_arc() {
@@ -851,7 +850,7 @@ mod tests {
851850
*state = 31337;
852851
// FIXME: #7372: hits type inference bug with iterators
853852
// send to other readers
854-
for uint::range(0, reader_convos.len()) |i| {
853+
foreach i in range(0u, reader_convos.len()) {
855854
match reader_convos[i] {
856855
(ref rc, _) => rc.send(()),
857856
}
@@ -861,7 +860,7 @@ mod tests {
861860
do (&read_mode).read |state| {
862861
// FIXME: #7372: hits type inference bug with iterators
863862
// complete handshake with other readers
864-
for uint::range(0, reader_convos.len()) |i| {
863+
foreach i in range(0u, reader_convos.len()) {
865864
match reader_convos[i] {
866865
(_, ref rp) => rp.recv(),
867866
}

src/libextra/arena.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl Arena {
277277
#[test]
278278
fn test_arena_destructors() {
279279
let arena = Arena();
280-
for uint::range(0, 10) |i| {
280+
foreach i in range(0u, 10) {
281281
// Arena allocate something with drop glue to make sure it
282282
// doesn't leak.
283283
do arena.alloc { @i };
@@ -293,7 +293,7 @@ fn test_arena_destructors() {
293293
fn test_arena_destructors_fail() {
294294
let arena = Arena();
295295
// Put some stuff in the arena.
296-
for uint::range(0, 10) |i| {
296+
foreach i in range(0u, 10) {
297297
// Arena allocate something with drop glue to make sure it
298298
// doesn't leak.
299299
do arena.alloc { @i };

src/libextra/bitv.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::ops;
1919
use std::uint;
2020
use std::vec;
2121

22-
2322
#[deriving(Clone)]
2423
struct SmallBitv {
2524
/// only the lowest nbits of this value are used. the rest is undefined.
@@ -146,7 +145,7 @@ impl BigBitv {
146145
let len = b.storage.len();
147146
assert_eq!(self.storage.len(), len);
148147
let mut changed = false;
149-
for uint::range(0, len) |i| {
148+
foreach i in range(0, len) {
150149
let mask = big_mask(nbits, i);
151150
let w0 = self.storage[i] & mask;
152151
let w1 = b.storage[i] & mask;
@@ -161,7 +160,7 @@ impl BigBitv {
161160

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

167166
#[inline]
@@ -511,7 +510,7 @@ impl Bitv {
511510
}
512511

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

517516
}
@@ -542,7 +541,7 @@ pub fn from_bools(bools: &[bool]) -> Bitv {
542541
*/
543542
pub fn from_fn(len: uint, f: &fn(index: uint) -> bool) -> Bitv {
544543
let mut bitv = Bitv::new(len, false);
545-
for uint::range(0, len) |i| {
544+
foreach i in range(0u, len) {
546545
bitv.set(i, f(i));
547546
}
548547
bitv
@@ -559,7 +558,7 @@ fn iterate_bits(base: uint, bits: uint, f: &fn(uint) -> bool) -> bool {
559558
if bits == 0 {
560559
return true;
561560
}
562-
for uint::range(0, uint::bits) |i| {
561+
foreach i in range(0u, uint::bits) {
563562
if bits & (1 << i) != 0 {
564563
if !f(base + i) {
565564
return false;
@@ -674,7 +673,7 @@ impl BitvSet {
674673
fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) {
675674
fn nbits(mut w: uint) -> uint {
676675
let mut bits = 0;
677-
for uint::range(0, uint::bits) |_| {
676+
foreach _ in range(0u, uint::bits) {
678677
if w == 0 {
679678
break;
680679
}
@@ -1283,12 +1282,12 @@ mod tests {
12831282
#[test]
12841283
fn test_equal_sneaky_big() {
12851284
let mut a = bitv::Bitv::new(100, false);
1286-
for uint::range(0, 100) |i| {
1285+
foreach i in range(0u, 100) {
12871286
a.set(i, true);
12881287
}
12891288
12901289
let mut b = bitv::Bitv::new(100, true);
1291-
for uint::range(0, 100) |i| {
1290+
foreach i in range(0u, 100) {
12921291
b.set(i, true);
12931292
}
12941293

src/libextra/container.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ pub trait Deque<T> : Mutable {
4141

4242
#[cfg(test)]
4343
mod bench {
44-
4544
use std::container::MutableMap;
46-
use std::{vec,rand,uint};
45+
use std::{vec, rand};
4746
use std::rand::RngUtil;
4847
use test::BenchHarness;
4948

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

5655
map.clear();
57-
for uint::range(0,n) |_i| {
56+
foreach _ in range(0, n) {
5857
map.insert(rng.gen::<uint>() % n, 1);
5958
}
6059

@@ -71,7 +70,7 @@ mod bench {
7170
bh: &mut BenchHarness) {
7271
// setup
7372
map.clear();
74-
for uint::range(0, n) |i| {
73+
foreach i in range(0u, n) {
7574
map.insert(i*2, 1);
7675
}
7776

@@ -109,7 +108,7 @@ mod bench {
109108
map: &mut M,
110109
bh: &mut BenchHarness) {
111110
// setup
112-
for uint::range(0, n) |i| {
111+
foreach i in range(0u, n) {
113112
map.insert(i, 1);
114113
}
115114

@@ -120,4 +119,4 @@ mod bench {
120119
i = (i + 1) % n;
121120
}
122121
}
123-
}
122+
}

src/libextra/crypto/sha2.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
12-
use std::uint;
13-
1411
use digest::Digest;
1512

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

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

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

255252
// add length
256253
if (self.W_idx > 14) {
257-
for uint::range(self.W_idx, 16) |_| {
254+
foreach _ in range(self.W_idx, 16) {
258255
self.process_word(0);
259256
}
260257
}
@@ -452,7 +449,7 @@ impl Engine256 {
452449
((x >> 17) | (x << 15)) ^ ((x >> 19) | (x << 13)) ^ (x >> 10)
453450
}
454451

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

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

537534
// add length
538535
if (self.W_idx > 14) {
539-
for uint::range(self.W_idx, 16) |_| {
536+
foreach _ in range(self.W_idx, 16) {
540537
self.process_word(0);
541538
}
542539
}

src/libextra/dlist.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ pub fn check_links<T>(list: &DList<T>) {
607607
mod tests {
608608
use super::*;
609609
use std::rand;
610-
use std::int;
611610
use extra::test;
612611

613612
#[test]
@@ -944,7 +943,7 @@ mod tests {
944943
fn fuzz_test(sz: int) {
945944
let mut m = DList::new::<int>();
946945
let mut v = ~[];
947-
for int::range(0i, sz) |i| {
946+
foreach i in range(0, sz) {
948947
check_links(&m);
949948
let r: u8 = rand::random();
950949
match r % 6 {

src/libextra/fileinput.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ mod test {
596596
input.next_file(); // skip the rest of 1
597597
598598
// read all lines from 1 (but don't read any from 2),
599-
for uint::range(1, 4) |i| {
599+
foreach i in range(1u, 4) {
600600
assert_eq!(input.read_line(), fmt!("1 %u", i));
601601
}
602602
// 1 is finished, but 2 hasn't been started yet, so this will

0 commit comments

Comments
 (0)