Skip to content

Commit d953a5c

Browse files
committed
replace old_iter::repeat with the Times trait
1 parent e91daaa commit d953a5c

13 files changed

+28
-54
lines changed

doc/tutorial.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ struct TimeBomb {
19771977
19781978
impl Drop for TimeBomb {
19791979
fn finalize(&self) {
1980-
for old_iter::repeat(self.explosivity) {
1980+
for self.explosivity.times {
19811981
println("blam!");
19821982
}
19831983
}

src/libcore/old_iter.rs

-20
Original file line numberDiff line numberDiff line change
@@ -238,26 +238,6 @@ pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
238238
// iter interface, such as would provide "reach" in addition to "each". As is,
239239
// it would have to be implemented with foldr, which is too inefficient.
240240

241-
#[inline(always)]
242-
#[cfg(stage0)]
243-
pub fn repeat(times: uint, blk: &fn() -> bool) {
244-
let mut i = 0;
245-
while i < times {
246-
if !blk() { break }
247-
i += 1;
248-
}
249-
}
250-
#[inline(always)]
251-
#[cfg(not(stage0))]
252-
pub fn repeat(times: uint, blk: &fn() -> bool) -> bool {
253-
let mut i = 0;
254-
while i < times {
255-
if !blk() { return false; }
256-
i += 1;
257-
}
258-
return true;
259-
}
260-
261241
#[inline(always)]
262242
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
263243
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {

src/libcore/task/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
619619
let ch = ch.clone();
620620
do spawn_unlinked {
621621
// Give middle task a chance to fail-but-not-kill-us.
622-
for old_iter::repeat(16) { task::yield(); }
622+
for 16.times { task::yield(); }
623623
ch.send(()); // If killed first, grandparent hangs.
624624
}
625625
fail!(); // Shouldn't kill either (grand)parent or (grand)child.
@@ -634,7 +634,7 @@ fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
634634
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
635635
do spawn_supervised { fail!(); }
636636
// Give child a chance to fail-but-not-kill-us.
637-
for old_iter::repeat(16) { task::yield(); }
637+
for 16.times { task::yield(); }
638638
}
639639
#[test] #[should_fail] #[ignore(cfg(windows))]
640640
fn test_spawn_unlinked_sup_fail_down() {
@@ -709,7 +709,7 @@ fn test_spawn_failure_propagate_grandchild() {
709709
loop { task::yield(); }
710710
}
711711
}
712-
for old_iter::repeat(16) { task::yield(); }
712+
for 16.times { task::yield(); }
713713
fail!();
714714
}
715715

@@ -721,7 +721,7 @@ fn test_spawn_failure_propagate_secondborn() {
721721
loop { task::yield(); }
722722
}
723723
}
724-
for old_iter::repeat(16) { task::yield(); }
724+
for 16.times { task::yield(); }
725725
fail!();
726726
}
727727

@@ -733,7 +733,7 @@ fn test_spawn_failure_propagate_nephew_or_niece() {
733733
loop { task::yield(); }
734734
}
735735
}
736-
for old_iter::repeat(16) { task::yield(); }
736+
for 16.times { task::yield(); }
737737
fail!();
738738
}
739739

@@ -745,7 +745,7 @@ fn test_spawn_linked_sup_propagate_sibling() {
745745
loop { task::yield(); }
746746
}
747747
}
748-
for old_iter::repeat(16) { task::yield(); }
748+
for 16.times { task::yield(); }
749749
fail!();
750750
}
751751

@@ -904,8 +904,7 @@ fn test_spawn_sched_blocking() {
904904

905905
// Testing that a task in one scheduler can block in foreign code
906906
// without affecting other schedulers
907-
for old_iter::repeat(20u) {
908-
907+
for 20u.times {
909908
let (start_po, start_ch) = stream();
910909
let (fin_po, fin_ch) = stream();
911910

@@ -1024,7 +1023,7 @@ fn test_unkillable() {
10241023

10251024
// We want to do this after failing
10261025
do spawn_unlinked {
1027-
for old_iter::repeat(10) { yield() }
1026+
for 10.times { yield() }
10281027
ch.send(());
10291028
}
10301029

@@ -1059,7 +1058,7 @@ fn test_unkillable_nested() {
10591058

10601059
// We want to do this after failing
10611060
do spawn_unlinked || {
1062-
for old_iter::repeat(10) { yield() }
1061+
for 10.times { yield() }
10631062
ch.send(());
10641063
}
10651064

src/librustdoc/markdown_pass.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ mod test {
629629
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
630630
write_markdown(doc, writer_factory);
631631
// We expect two pages to have been written
632-
for old_iter::repeat(2) {
632+
for 2.times {
633633
po.recv();
634634
}
635635
}
@@ -641,7 +641,7 @@ mod test {
641641
~"#[link(name = \"core\")]; mod a { }");
642642
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
643643
write_markdown(doc, writer_factory);
644-
for old_iter::repeat(2) {
644+
for 2.times {
645645
let (page, markdown) = po.recv();
646646
match page {
647647
doc::CratePage(_) => {

src/libstd/base64.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
//! Base64 binary-to-text encoding
1212
13-
use core::old_iter;
14-
use core::str;
15-
use core::vec;
16-
1713
pub trait ToBase64 {
1814
fn to_base64(&self) -> ~str;
1915
}
@@ -152,7 +148,7 @@ impl FromBase64 for ~[u8] {
152148
while i < len {
153149
let mut n = 0u;
154150

155-
for old_iter::repeat(4u) {
151+
for 4u.times {
156152
let ch = self[i] as char;
157153
n <<= 6u;
158154

src/libstd/timer.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ mod test {
188188
#[test]
189189
fn test_gl_timer_sleep_stress1() {
190190
let hl_loop = &uv::global_loop::get();
191-
for old_iter::repeat(50u) {
191+
for 50u.times {
192192
sleep(hl_loop, 1u);
193193
}
194194
}
@@ -208,8 +208,7 @@ mod test {
208208

209209
};
210210

211-
for old_iter::repeat(repeat) {
212-
211+
for repeat.times {
213212
let ch = ch.clone();
214213
for spec.each |spec| {
215214
let (times, maxms) = *spec;
@@ -218,15 +217,15 @@ mod test {
218217
do task::spawn {
219218
use core::rand::*;
220219
let mut rng = rng();
221-
for old_iter::repeat(times) {
220+
for times.times {
222221
sleep(&hl_loop_clone, rng.next() as uint % maxms);
223222
}
224223
ch.send(());
225224
}
226225
}
227226
}
228227

229-
for old_iter::repeat(repeat * spec.len()) {
228+
for (repeat * spec.len()).times {
230229
po.recv()
231230
}
232231
}
@@ -244,7 +243,7 @@ mod test {
244243
let mut failures = 0;
245244
let hl_loop = uv::global_loop::get();
246245

247-
for old_iter::repeat(times as uint) {
246+
for (times as uint).times {
248247
task::yield();
249248

250249
let expected = rand::rng().gen_str(16u);
@@ -273,7 +272,7 @@ mod test {
273272
let mut failures = 0;
274273
let hl_loop = uv::global_loop::get();
275274

276-
for old_iter::repeat(times as uint) {
275+
for (times as uint).times {
277276
let mut rng = rand::rng();
278277
let expected = Cell(rng.gen_str(16u));
279278
let (test_po, test_ch) = stream::<~str>();

src/libstd/uv_global_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ mod test {
215215
let (exit_po, exit_ch) = stream::<()>();
216216
let exit_ch = SharedChan::new(exit_ch);
217217
let cycles = 5000u;
218-
for old_iter::repeat(cycles) {
218+
for cycles.times {
219219
let exit_ch_clone = exit_ch.clone();
220220
task::spawn_sched(task::ManualThreads(1u), || {
221221
let hl_loop = &get_gl();
222222
impl_uv_hl_simple_timer(hl_loop);
223223
exit_ch_clone.send(());
224224
});
225225
};
226-
for old_iter::repeat(cycles) {
226+
for cycles.times {
227227
exit_po.recv();
228228
};
229229
debug!(~"test_stress_gl_uv_global_loop_high_level_global_timer"+

src/libstd/uv_iotask.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ fn test_uv_iotask_async() {
284284
// impl_uv_hl_async() runs have been called, at least.
285285
let (work_exit_po, work_exit_ch) = stream::<()>();
286286
let work_exit_ch = SharedChan::new(work_exit_ch);
287-
for old_iter::repeat(7u) {
287+
for 7u.times {
288288
let iotask_clone = iotask.clone();
289289
let work_exit_ch_clone = work_exit_ch.clone();
290290
do task::spawn_sched(task::ManualThreads(1u)) {
@@ -294,7 +294,7 @@ fn test_uv_iotask_async() {
294294
work_exit_ch_clone.send(());
295295
};
296296
};
297-
for old_iter::repeat(7u) {
297+
for 7u.times {
298298
debug!("waiting");
299299
work_exit_po.recv();
300300
};

src/test/bench/task-perf-alloc-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
}
3131

3232
fn run(repeat: int, depth: int) {
33-
for old_iter::repeat(repeat as uint) {
33+
for (repeat as uint).times {
3434
debug!("starting %.4f", precise_time_s());
3535
do task::try {
3636
recurse_or_fail(depth, None)

src/test/run-fail/extern-fail.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn count(n: uint) -> uint {
3737
}
3838

3939
fn main() {
40-
for old_iter::repeat(10u) {
40+
for 10u.times {
4141
do task::spawn {
4242
let result = count(5u);
4343
debug!("result = %?", result);

src/test/run-pass/bitv-perf-test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ fn bitv_test() -> bool {
2121
}
2222

2323
pub fn main() {
24-
do old_iter::repeat(10000) || {bitv_test()};
24+
do 10000.times || {bitv_test()};
2525
}

src/test/run-pass/extern-stress.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn count(n: uint) -> uint {
3434
}
3535

3636
pub fn main() {
37-
for old_iter::repeat(100u) {
37+
for 100u.times {
3838
do task::spawn {
3939
assert!(count(5u) == 16u);
4040
};

src/test/run-pass/extern-yield.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn count(n: uint) -> uint {
3131
}
3232

3333
pub fn main() {
34-
for old_iter::repeat(10u) {
34+
for 10u.times {
3535
do task::spawn {
3636
let result = count(5u);
3737
debug!("result = %?", result);

0 commit comments

Comments
 (0)