auto merge of #6106 : thestinger/rust/iter, r=bstrie
I don't have a strong opinion on the function vs. method, but there's no point in having both. I'd like to make a `repeat` adaptor like Python/Haskell for turning a value into an infinite stream of the value, so this has to at least be renamed.
This commit is contained in:
commit
9f671698e6
13 changed files with 28 additions and 54 deletions
|
@ -1977,7 +1977,7 @@ struct TimeBomb {
|
||||||
|
|
||||||
impl Drop for TimeBomb {
|
impl Drop for TimeBomb {
|
||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
for old_iter::repeat(self.explosivity) {
|
for self.explosivity.times {
|
||||||
println("blam!");
|
println("blam!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,26 +238,6 @@ pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
|
||||||
// iter interface, such as would provide "reach" in addition to "each". As is,
|
// iter interface, such as would provide "reach" in addition to "each". As is,
|
||||||
// it would have to be implemented with foldr, which is too inefficient.
|
// it would have to be implemented with foldr, which is too inefficient.
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
#[cfg(stage0)]
|
|
||||||
pub fn repeat(times: uint, blk: &fn() -> bool) {
|
|
||||||
let mut i = 0;
|
|
||||||
while i < times {
|
|
||||||
if !blk() { break }
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[inline(always)]
|
|
||||||
#[cfg(not(stage0))]
|
|
||||||
pub fn repeat(times: uint, blk: &fn() -> bool) -> bool {
|
|
||||||
let mut i = 0;
|
|
||||||
while i < times {
|
|
||||||
if !blk() { return false; }
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
|
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
|
||||||
|
|
|
@ -635,7 +635,7 @@ fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port
|
||||||
let ch = ch.clone();
|
let ch = ch.clone();
|
||||||
do spawn_unlinked {
|
do spawn_unlinked {
|
||||||
// Give middle task a chance to fail-but-not-kill-us.
|
// Give middle task a chance to fail-but-not-kill-us.
|
||||||
for old_iter::repeat(16) { task::yield(); }
|
for 16.times { task::yield(); }
|
||||||
ch.send(()); // If killed first, grandparent hangs.
|
ch.send(()); // If killed first, grandparent hangs.
|
||||||
}
|
}
|
||||||
fail!(); // Shouldn't kill either (grand)parent or (grand)child.
|
fail!(); // Shouldn't kill either (grand)parent or (grand)child.
|
||||||
|
@ -650,7 +650,7 @@ fn test_spawn_unlinked_unsup_no_fail_up() { // child unlinked fails
|
||||||
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
|
fn test_spawn_unlinked_sup_no_fail_up() { // child unlinked fails
|
||||||
do spawn_supervised { fail!(); }
|
do spawn_supervised { fail!(); }
|
||||||
// Give child a chance to fail-but-not-kill-us.
|
// Give child a chance to fail-but-not-kill-us.
|
||||||
for old_iter::repeat(16) { task::yield(); }
|
for 16.times { task::yield(); }
|
||||||
}
|
}
|
||||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||||
fn test_spawn_unlinked_sup_fail_down() {
|
fn test_spawn_unlinked_sup_fail_down() {
|
||||||
|
@ -725,7 +725,7 @@ fn test_spawn_failure_propagate_grandchild() {
|
||||||
loop { task::yield(); }
|
loop { task::yield(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for old_iter::repeat(16) { task::yield(); }
|
for 16.times { task::yield(); }
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -737,7 +737,7 @@ fn test_spawn_failure_propagate_secondborn() {
|
||||||
loop { task::yield(); }
|
loop { task::yield(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for old_iter::repeat(16) { task::yield(); }
|
for 16.times { task::yield(); }
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,7 +749,7 @@ fn test_spawn_failure_propagate_nephew_or_niece() {
|
||||||
loop { task::yield(); }
|
loop { task::yield(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for old_iter::repeat(16) { task::yield(); }
|
for 16.times { task::yield(); }
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,7 +761,7 @@ fn test_spawn_linked_sup_propagate_sibling() {
|
||||||
loop { task::yield(); }
|
loop { task::yield(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for old_iter::repeat(16) { task::yield(); }
|
for 16.times { task::yield(); }
|
||||||
fail!();
|
fail!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,8 +920,7 @@ fn test_spawn_sched_blocking() {
|
||||||
|
|
||||||
// Testing that a task in one scheduler can block in foreign code
|
// Testing that a task in one scheduler can block in foreign code
|
||||||
// without affecting other schedulers
|
// without affecting other schedulers
|
||||||
for old_iter::repeat(20u) {
|
for 20u.times {
|
||||||
|
|
||||||
let (start_po, start_ch) = stream();
|
let (start_po, start_ch) = stream();
|
||||||
let (fin_po, fin_ch) = stream();
|
let (fin_po, fin_ch) = stream();
|
||||||
|
|
||||||
|
@ -1040,7 +1039,7 @@ fn test_unkillable() {
|
||||||
|
|
||||||
// We want to do this after failing
|
// We want to do this after failing
|
||||||
do spawn_unlinked {
|
do spawn_unlinked {
|
||||||
for old_iter::repeat(10) { yield() }
|
for 10.times { yield() }
|
||||||
ch.send(());
|
ch.send(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1075,7 +1074,7 @@ fn test_unkillable_nested() {
|
||||||
|
|
||||||
// We want to do this after failing
|
// We want to do this after failing
|
||||||
do spawn_unlinked || {
|
do spawn_unlinked || {
|
||||||
for old_iter::repeat(10) { yield() }
|
for 10.times { yield() }
|
||||||
ch.send(());
|
ch.send(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -629,7 +629,7 @@ mod test {
|
||||||
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
|
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
|
||||||
write_markdown(doc, writer_factory);
|
write_markdown(doc, writer_factory);
|
||||||
// We expect two pages to have been written
|
// We expect two pages to have been written
|
||||||
for old_iter::repeat(2) {
|
for 2.times {
|
||||||
po.recv();
|
po.recv();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -641,7 +641,7 @@ mod test {
|
||||||
~"#[link(name = \"core\")]; mod a { }");
|
~"#[link(name = \"core\")]; mod a { }");
|
||||||
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
|
let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc);
|
||||||
write_markdown(doc, writer_factory);
|
write_markdown(doc, writer_factory);
|
||||||
for old_iter::repeat(2) {
|
for 2.times {
|
||||||
let (page, markdown) = po.recv();
|
let (page, markdown) = po.recv();
|
||||||
match page {
|
match page {
|
||||||
doc::CratePage(_) => {
|
doc::CratePage(_) => {
|
||||||
|
|
|
@ -10,10 +10,6 @@
|
||||||
|
|
||||||
//! Base64 binary-to-text encoding
|
//! Base64 binary-to-text encoding
|
||||||
|
|
||||||
use core::old_iter;
|
|
||||||
use core::str;
|
|
||||||
use core::vec;
|
|
||||||
|
|
||||||
pub trait ToBase64 {
|
pub trait ToBase64 {
|
||||||
fn to_base64(&self) -> ~str;
|
fn to_base64(&self) -> ~str;
|
||||||
}
|
}
|
||||||
|
@ -152,7 +148,7 @@ impl FromBase64 for ~[u8] {
|
||||||
while i < len {
|
while i < len {
|
||||||
let mut n = 0u;
|
let mut n = 0u;
|
||||||
|
|
||||||
for old_iter::repeat(4u) {
|
for 4u.times {
|
||||||
let ch = self[i] as char;
|
let ch = self[i] as char;
|
||||||
n <<= 6u;
|
n <<= 6u;
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gl_timer_sleep_stress1() {
|
fn test_gl_timer_sleep_stress1() {
|
||||||
let hl_loop = &uv::global_loop::get();
|
let hl_loop = &uv::global_loop::get();
|
||||||
for old_iter::repeat(50u) {
|
for 50u.times {
|
||||||
sleep(hl_loop, 1u);
|
sleep(hl_loop, 1u);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,8 +208,7 @@ mod test {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for old_iter::repeat(repeat) {
|
for repeat.times {
|
||||||
|
|
||||||
let ch = ch.clone();
|
let ch = ch.clone();
|
||||||
for spec.each |spec| {
|
for spec.each |spec| {
|
||||||
let (times, maxms) = *spec;
|
let (times, maxms) = *spec;
|
||||||
|
@ -218,7 +217,7 @@ mod test {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
use core::rand::*;
|
use core::rand::*;
|
||||||
let mut rng = rng();
|
let mut rng = rng();
|
||||||
for old_iter::repeat(times) {
|
for times.times {
|
||||||
sleep(&hl_loop_clone, rng.next() as uint % maxms);
|
sleep(&hl_loop_clone, rng.next() as uint % maxms);
|
||||||
}
|
}
|
||||||
ch.send(());
|
ch.send(());
|
||||||
|
@ -226,7 +225,7 @@ mod test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for old_iter::repeat(repeat * spec.len()) {
|
for (repeat * spec.len()).times {
|
||||||
po.recv()
|
po.recv()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,7 +243,7 @@ mod test {
|
||||||
let mut failures = 0;
|
let mut failures = 0;
|
||||||
let hl_loop = uv::global_loop::get();
|
let hl_loop = uv::global_loop::get();
|
||||||
|
|
||||||
for old_iter::repeat(times as uint) {
|
for (times as uint).times {
|
||||||
task::yield();
|
task::yield();
|
||||||
|
|
||||||
let expected = rand::rng().gen_str(16u);
|
let expected = rand::rng().gen_str(16u);
|
||||||
|
@ -273,7 +272,7 @@ mod test {
|
||||||
let mut failures = 0;
|
let mut failures = 0;
|
||||||
let hl_loop = uv::global_loop::get();
|
let hl_loop = uv::global_loop::get();
|
||||||
|
|
||||||
for old_iter::repeat(times as uint) {
|
for (times as uint).times {
|
||||||
let mut rng = rand::rng();
|
let mut rng = rand::rng();
|
||||||
let expected = Cell(rng.gen_str(16u));
|
let expected = Cell(rng.gen_str(16u));
|
||||||
let (test_po, test_ch) = stream::<~str>();
|
let (test_po, test_ch) = stream::<~str>();
|
||||||
|
|
|
@ -215,7 +215,7 @@ mod test {
|
||||||
let (exit_po, exit_ch) = stream::<()>();
|
let (exit_po, exit_ch) = stream::<()>();
|
||||||
let exit_ch = SharedChan::new(exit_ch);
|
let exit_ch = SharedChan::new(exit_ch);
|
||||||
let cycles = 5000u;
|
let cycles = 5000u;
|
||||||
for old_iter::repeat(cycles) {
|
for cycles.times {
|
||||||
let exit_ch_clone = exit_ch.clone();
|
let exit_ch_clone = exit_ch.clone();
|
||||||
task::spawn_sched(task::ManualThreads(1u), || {
|
task::spawn_sched(task::ManualThreads(1u), || {
|
||||||
let hl_loop = &get_gl();
|
let hl_loop = &get_gl();
|
||||||
|
@ -223,7 +223,7 @@ mod test {
|
||||||
exit_ch_clone.send(());
|
exit_ch_clone.send(());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
for old_iter::repeat(cycles) {
|
for cycles.times {
|
||||||
exit_po.recv();
|
exit_po.recv();
|
||||||
};
|
};
|
||||||
debug!(~"test_stress_gl_uv_global_loop_high_level_global_timer"+
|
debug!(~"test_stress_gl_uv_global_loop_high_level_global_timer"+
|
||||||
|
|
|
@ -284,7 +284,7 @@ fn test_uv_iotask_async() {
|
||||||
// impl_uv_hl_async() runs have been called, at least.
|
// impl_uv_hl_async() runs have been called, at least.
|
||||||
let (work_exit_po, work_exit_ch) = stream::<()>();
|
let (work_exit_po, work_exit_ch) = stream::<()>();
|
||||||
let work_exit_ch = SharedChan::new(work_exit_ch);
|
let work_exit_ch = SharedChan::new(work_exit_ch);
|
||||||
for old_iter::repeat(7u) {
|
for 7u.times {
|
||||||
let iotask_clone = iotask.clone();
|
let iotask_clone = iotask.clone();
|
||||||
let work_exit_ch_clone = work_exit_ch.clone();
|
let work_exit_ch_clone = work_exit_ch.clone();
|
||||||
do task::spawn_sched(task::ManualThreads(1u)) {
|
do task::spawn_sched(task::ManualThreads(1u)) {
|
||||||
|
@ -294,7 +294,7 @@ fn test_uv_iotask_async() {
|
||||||
work_exit_ch_clone.send(());
|
work_exit_ch_clone.send(());
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
for old_iter::repeat(7u) {
|
for 7u.times {
|
||||||
debug!("waiting");
|
debug!("waiting");
|
||||||
work_exit_po.recv();
|
work_exit_po.recv();
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(repeat: int, depth: int) {
|
fn run(repeat: int, depth: int) {
|
||||||
for old_iter::repeat(repeat as uint) {
|
for (repeat as uint).times {
|
||||||
debug!("starting %.4f", precise_time_s());
|
debug!("starting %.4f", precise_time_s());
|
||||||
do task::try {
|
do task::try {
|
||||||
recurse_or_fail(depth, None)
|
recurse_or_fail(depth, None)
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn count(n: uint) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
for old_iter::repeat(10u) {
|
for 10u.times {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
let result = count(5u);
|
let result = count(5u);
|
||||||
debug!("result = %?", result);
|
debug!("result = %?", result);
|
||||||
|
|
|
@ -21,5 +21,5 @@ fn bitv_test() -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
do old_iter::repeat(10000) || {bitv_test()};
|
do 10000.times || {bitv_test()};
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn count(n: uint) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
for old_iter::repeat(100u) {
|
for 100u.times {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
assert_eq!(count(5u), 16u);
|
assert_eq!(count(5u), 16u);
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ fn count(n: uint) -> uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
for old_iter::repeat(10u) {
|
for 10u.times {
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
let result = count(5u);
|
let result = count(5u);
|
||||||
debug!("result = %?", result);
|
debug!("result = %?", result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue