extra: Replace for with do { .. } expr where internal iterators are used

This commit is contained in:
blake2-ppc 2013-07-31 21:07:44 +02:00
parent b18bd785ec
commit dbcb74e247
5 changed files with 47 additions and 36 deletions

View File

@ -72,11 +72,12 @@ impl Drop for Arena {
fn drop(&self) {
unsafe {
destroy_chunk(&self.head);
for self.chunks.each |chunk| {
do self.chunks.each |chunk| {
if !chunk.is_pod {
destroy_chunk(chunk);
}
}
true
};
}
}
}

View File

@ -646,9 +646,10 @@ impl BitvSet {
/// Creates a new bit vector set from the given bit vector
pub fn from_bitv(bitv: Bitv) -> BitvSet {
let mut size = 0;
for bitv.ones |_| {
do bitv.ones |_| {
size += 1;
}
true
};
let Bitv{rep, _} = bitv;
match rep {
Big(b) => BitvSet{ size: size, bitv: b },
@ -1354,18 +1355,18 @@ mod tests {
fn test_small_clear() {
let mut b = Bitv::new(14, true);
b.clear();
for b.ones |i| {
fail!("found 1 at %?", i);
}
do b.ones |i| {
fail!("found 1 at %?", i)
};
}
#[test]
fn test_big_clear() {
let mut b = Bitv::new(140, true);
b.clear();
for b.ones |i| {
fail!("found 1 at %?", i);
}
do b.ones |i| {
fail!("found 1 at %?", i)
};
}
#[test]
@ -1400,10 +1401,11 @@ mod tests {
let mut i = 0;
let expected = [3, 5, 11, 77];
for a.intersection(&b) |x| {
do a.intersection(&b) |x| {
assert_eq!(*x, expected[i]);
i += 1
}
i += 1;
true
};
assert_eq!(i, expected.len());
}
@ -1423,10 +1425,11 @@ mod tests {
let mut i = 0;
let expected = [1, 5, 500];
for a.difference(&b) |x| {
do a.difference(&b) |x| {
assert_eq!(*x, expected[i]);
i += 1
}
i += 1;
true
};
assert_eq!(i, expected.len());
}
@ -1448,10 +1451,11 @@ mod tests {
let mut i = 0;
let expected = [1, 5, 11, 14, 220];
for a.symmetric_difference(&b) |x| {
do a.symmetric_difference(&b) |x| {
assert_eq!(*x, expected[i]);
i += 1
}
i += 1;
true
};
assert_eq!(i, expected.len());
}
@ -1476,10 +1480,11 @@ mod tests {
let mut i = 0;
let expected = [1, 3, 5, 9, 11, 13, 19, 24, 160];
for a.union(&b) |x| {
do a.union(&b) |x| {
assert_eq!(*x, expected[i]);
i += 1
}
i += 1;
true
};
assert_eq!(i, expected.len());
}

View File

@ -678,9 +678,10 @@ pub mod groups {
// FIXME: #5516
let mut desc_rows = ~[];
for each_split_within(desc_normalized_whitespace, 54) |substr| {
do each_split_within(desc_normalized_whitespace, 54) |substr| {
desc_rows.push(substr.to_owned());
}
true
};
// FIXME: #5516
// wrapped description
@ -780,7 +781,7 @@ pub mod groups {
priv fn test_split_within() {
fn t(s: &str, i: uint, u: &[~str]) {
let mut v = ~[];
for each_split_within(s, i) |s| { v.push(s.to_owned()) }
do each_split_within(s, i) |s| { v.push(s.to_owned()); true };
assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
}
t("", 0, []);

View File

@ -70,10 +70,11 @@ pub fn find<T:Clone>(ls: @List<T>, f: &fn(&T) -> bool) -> Option<T> {
/// Returns true if a list contains an element with the given value
pub fn has<T:Eq>(ls: @List<T>, elt: T) -> bool {
for each(ls) |e| {
if *e == elt { return true; }
}
return false;
let mut found = false;
do each(ls) |e| {
if *e == elt { found = true; false } else { true }
};
return found;
}
/// Returns true if the list is empty

View File

@ -1001,11 +1001,12 @@ mod test_treemap {
assert!(m.insert(1, 2));
let mut n = 4;
for m.each_reverse |k, v| {
do m.each_reverse |k, v| {
assert_eq!(*k, n);
assert_eq!(*v, n * 2);
n -= 1;
}
true
};
}
#[test]
@ -1277,10 +1278,11 @@ mod test_set {
assert!(m.insert(1));
let mut n = 4;
for m.each_reverse |x| {
do m.each_reverse |x| {
assert_eq!(*x, n);
n -= 1
}
n -= 1;
true
};
}
fn check(a: &[int], b: &[int], expected: &[int],
@ -1292,10 +1294,11 @@ mod test_set {
foreach y in b.iter() { assert!(set_b.insert(*y)) }
let mut i = 0;
for f(&set_a, &set_b) |x| {
do f(&set_a, &set_b) |x| {
assert_eq!(*x, expected[i]);
i += 1;
}
true
};
assert_eq!(i, expected.len());
}