Skip to content

Commit b8fa9d3

Browse files
committed
auto merge of #7015 : huonw/rust/each-fn-kill, r=thestinger
Continuation of #6995/#6999.
2 parents e2ec8e7 + 98ba91f commit b8fa9d3

Some content is hidden

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

79 files changed

+449
-952
lines changed

doc/tutorial-tasks.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,11 @@ a single large vector of floats. Each task needs the full vector to perform its
351351
# use std::vec;
352352
# use std::uint;
353353
# use std::rand;
354+
# use std::iterator::IteratorUtil;
354355
use extra::arc::ARC;
355356
356357
fn pnorm(nums: &~[float], p: uint) -> float {
357-
(vec::foldl(0.0, *nums, |a,b| a+(*b).pow(p as float) )).pow(1f / (p as float))
358+
nums.iter().fold(0.0, |a,b| a+(*b).pow(p as float) ).pow(1f / (p as float))
358359
}
359360
360361
fn main() {

src/compiletest/procsrv.rs

-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@
1010

1111
use core::prelude::*;
1212

13-
use core::comm;
14-
use core::io;
15-
use core::libc::c_int;
1613
use core::os;
1714
use core::run;
1815
use core::str;
19-
use core::task;
20-
use core::vec;
2116

2217
#[cfg(target_os = "win32")]
2318
fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
@@ -74,4 +69,3 @@ pub fn run(lib_path: &str,
7469
err: str::from_bytes(output.error)
7570
}
7671
}
77-

src/compiletest/runtest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use procsrv;
2222
use util;
2323
use util::logv;
2424

25+
use core::iterator::IteratorUtil;
2526
use core::io;
2627
use core::os;
2728
use core::str;
@@ -780,7 +781,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
780781
Some(~""));
781782

782783
let mut exitcode : int = 0;
783-
for str::each_char(exitcode_out) |c| {
784+
for exitcode_out.iter().advance |c| {
784785
if !c.is_digit() { break; }
785786
exitcode = exitcode * 10 + match c {
786787
'0' .. '9' => c as int - ('0' as int),

src/libextra/dlist.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.
2020

2121
use core::prelude::*;
2222

23+
use core::iterator::IteratorUtil;
2324
use core::managed;
2425
use core::old_iter;
2526
use core::vec;
@@ -110,7 +111,7 @@ pub fn from_elem<T>(data: T) -> @mut DList<T> {
110111

111112
/// Creates a new dlist from a vector of elements, maintaining the same order
112113
pub fn from_vec<T:Copy>(vec: &[T]) -> @mut DList<T> {
113-
do vec::foldl(DList(), vec) |list,data| {
114+
do vec.iter().fold(DList()) |list,data| {
114115
list.push(*data); // Iterating left-to-right -- add newly to the tail.
115116
list
116117
}

src/libextra/fileinput.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ mod test {
414414
415415
use super::{FileInput, pathify, input_vec, input_vec_state};
416416
417+
use core::iterator::IteratorUtil;
417418
use core::io;
418419
use core::str;
419420
use core::uint;
@@ -455,7 +456,7 @@ mod test {
455456
456457
let fi = FileInput::from_vec(copy filenames);
457458
458-
for "012".each_chari |line, c| {
459+
for "012".iter().enumerate().advance |(line, c)| {
459460
assert_eq!(fi.read_byte(), c as int);
460461
assert_eq!(fi.state().line_num, line);
461462
assert_eq!(fi.state().line_num_file, 0);

src/libextra/flate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Simple compression
1616

1717
#[allow(missing_doc)];
1818

19-
use core::prelude::*;
20-
2119
use core::libc::{c_void, size_t, c_int};
2220
use core::libc;
2321
use core::vec;
@@ -87,6 +85,7 @@ mod tests {
8785
use super::*;
8886
use core::rand;
8987
use core::rand::RngUtil;
88+
use core::prelude::*;
9089

9190
#[test]
9291
#[allow(non_implicitly_copyable_typarams)]

src/libextra/flatpipes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,6 @@ mod test {
654654
use core::int;
655655
use core::io::BytesWriter;
656656
use core::result;
657-
use core::sys;
658657
use core::task;
659658

660659
#[test]

src/libextra/json.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
use core::prelude::*;
2020

21+
use core::iterator::IteratorUtil;
2122
use core::char;
2223
use core::float;
2324
use core::hashmap::HashMap;
@@ -58,7 +59,7 @@ pub struct Error {
5859

5960
fn escape_str(s: &str) -> ~str {
6061
let mut escaped = ~"\"";
61-
for str::each_char(s) |c| {
62+
for s.iter().advance |c| {
6263
match c {
6364
'"' => escaped += "\\\"",
6465
'\\' => escaped += "\\\\",
@@ -913,7 +914,8 @@ impl serialize::Decoder for Decoder {
913914

914915
fn read_char(&mut self) -> char {
915916
let mut v = ~[];
916-
for str::each_char(self.read_str()) |c| { v.push(c) }
917+
let s = self.read_str();
918+
for s.iter().advance |c| { v.push(c) }
917919
if v.len() != 1 { fail!("string must have one character") }
918920
v[0]
919921
}

src/libextra/list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use core::prelude::*;
1414

15-
use core::vec;
15+
use core::iterator::IteratorUtil;
1616

1717
#[deriving(Eq)]
1818
pub enum List<T> {
@@ -28,7 +28,7 @@ pub enum MutList<T> {
2828

2929
/// Create a list from a vector
3030
pub fn from_vec<T:Copy>(v: &[T]) -> @List<T> {
31-
vec::foldr(v, @Nil::<T>, |h, t| @Cons(*h, t))
31+
v.rev_iter().fold(@Nil::<T>, |t, h| @Cons(*h, t))
3232
}
3333

3434
/**

src/libextra/net_url.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use core::prelude::*;
1616

17+
use core::iterator::IteratorUtil;
1718
use core::cmp::Eq;
1819
use core::io::{Reader, ReaderUtil};
1920
use core::io;
@@ -358,7 +359,7 @@ pub fn query_to_str(query: &Query) -> ~str {
358359

359360
// returns the scheme and the rest of the url, or a parsing error
360361
pub fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> {
361-
for str::each_chari(rawurl) |i,c| {
362+
for rawurl.iter().enumerate().advance |(i,c)| {
362363
match c {
363364
'A' .. 'Z' | 'a' .. 'z' => loop,
364365
'0' .. '9' | '+' | '-' | '.' => {
@@ -418,7 +419,7 @@ fn get_authority(rawurl: &str) ->
418419
let mut colon_count = 0;
419420
let mut (pos, begin, end) = (0, 2, len);
420421

421-
for str::each_chari(rawurl) |i,c| {
422+
for rawurl.iter().enumerate().advance |(i,c)| {
422423
if i < 2 { loop; } // ignore the leading //
423424

424425
// deal with input class first
@@ -562,7 +563,7 @@ fn get_path(rawurl: &str, authority: bool) ->
562563
Result<(~str, ~str), ~str> {
563564
let len = str::len(rawurl);
564565
let mut end = len;
565-
for str::each_chari(rawurl) |i,c| {
566+
for rawurl.iter().enumerate().advance |(i,c)| {
566567
match c {
567568
'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '&' |'\'' | '(' | ')' | '.'
568569
| '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '='

src/libextra/num/bigint.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ A BigInt is a combination of BigUint and Sign.
1919
#[allow(missing_doc)];
2020

2121
use core::prelude::*;
22-
22+
use core::iterator::IteratorUtil;
2323
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2424
use core::int;
2525
use core::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
@@ -129,12 +129,9 @@ impl TotalOrd for BigUint {
129129
if s_len < o_len { return Less; }
130130
if s_len > o_len { return Greater; }
131131

132-
for self.data.eachi_reverse |i, elm| {
133-
match (*elm, other.data[i]) {
134-
(l, r) if l < r => return Less,
135-
(l, r) if l > r => return Greater,
136-
_ => loop
137-
};
132+
for self.data.rev_iter().zip(other.data.rev_iter()).advance |(&self_i, &other_i)| {
133+
cond!((self_i < other_i) { return Less; }
134+
(self_i > other_i) { return Greater; })
138135
}
139136
return Equal;
140137
}
@@ -421,7 +418,7 @@ impl Integer for BigUint {
421418
let bn = *b.data.last();
422419
let mut d = ~[];
423420
let mut carry = 0;
424-
for an.each_reverse |elt| {
421+
for an.rev_iter().advance |elt| {
425422
let ai = BigDigit::to_uint(carry, *elt);
426423
let di = ai / (bn as uint);
427424
assert!(di < BigDigit::base);
@@ -648,7 +645,7 @@ impl BigUint {
648645

649646
let mut borrow = 0;
650647
let mut shifted = ~[];
651-
for self.data.each_reverse |elem| {
648+
for self.data.rev_iter().advance |elem| {
652649
shifted = ~[(*elem >> n_bits) | borrow] + shifted;
653650
borrow = *elem << (BigDigit::bits - n_bits);
654651
}

src/libextra/par.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use core::prelude::*;
1212

13+
use core::iterator::IteratorUtil;
1314
use core::cast;
1415
use core::ptr;
1516
use core::sys;
@@ -122,25 +123,24 @@ pub fn alli<A:Copy + Owned>(
122123
xs: &[A],
123124
fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
124125
{
125-
do vec::all(map_slices(xs, || {
126+
let mapped = map_slices(xs, || {
126127
let f = fn_factory();
127128
let result: ~fn(uint, &[A]) -> bool = |base, slice| {
128-
vec::alli(slice, |i, x| {
129-
f(i + base, x)
130-
})
129+
slice.iter().enumerate().all(|(i, x)| f(i + base, x))
131130
};
132131
result
133-
})) |x| { *x }
132+
});
133+
mapped.iter().all(|&x| x)
134134
}
135135

136136
/// Returns true if the function holds for any elements in the vector.
137137
pub fn any<A:Copy + Owned>(
138138
xs: &[A],
139139
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
140-
do vec::any(map_slices(xs, || {
140+
let mapped = map_slices(xs, || {
141141
let f = fn_factory();
142-
let result: ~fn(uint, &[A]) -> bool =
143-
|_, slice| vec::any(slice, |x| f(x));
142+
let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f);
144143
result
145-
})) |x| { *x }
144+
});
145+
mapped.iter().any(|&x| x)
146146
}

src/libextra/sort.rs

-3
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,8 @@ mod test_tim_sort {
929929
use core::prelude::*;
930930

931931
use sort::tim_sort;
932-
933-
use core::local_data;
934932
use core::rand::RngUtil;
935933
use core::rand;
936-
use core::uint;
937934
use core::vec;
938935

939936
struct CVal {

src/libextra/stats.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use core::prelude::*;
1414

15+
use core::iterator::*;
1516
use core::vec;
1617
use core::f64;
1718
use core::cmp;
@@ -36,17 +37,17 @@ pub trait Stats {
3637

3738
impl<'self> Stats for &'self [f64] {
3839
fn sum(self) -> f64 {
39-
vec::foldl(0.0, self, |p,q| p + *q)
40+
self.iter().fold(0.0, |p,q| p + *q)
4041
}
4142

4243
fn min(self) -> f64 {
4344
assert!(self.len() != 0);
44-
vec::foldl(self[0], self, |p,q| cmp::min(p, *q))
45+
self.iter().fold(self[0], |p,q| cmp::min(p, *q))
4546
}
4647

4748
fn max(self) -> f64 {
4849
assert!(self.len() != 0);
49-
vec::foldl(self[0], self, |p,q| cmp::max(p, *q))
50+
self.iter().fold(self[0], |p,q| cmp::max(p, *q))
5051
}
5152

5253
fn mean(self) -> f64 {

src/libextra/std.rc

-1
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,3 @@ pub mod extra {
148148
pub use serialize;
149149
pub use test;
150150
}
151-

src/libextra/sync.rs

-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ mod tests {
731731
use core::cast;
732732
use core::cell::Cell;
733733
use core::comm;
734-
use core::ptr;
735734
use core::result;
736735
use core::task;
737736
use core::vec;

src/libextra/tempfile.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ mod tests {
3434
use core::prelude::*;
3535

3636
use tempfile::mkdtemp;
37-
use tempfile;
3837

3938
use core::os;
4039
use core::str;

src/libextra/time.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use core::i32;
1616
use core::int;
1717
use core::io;
1818
use core::str;
19+
use core::iterator::IteratorUtil;
1920

2021
static NSEC_PER_SEC: i32 = 1_000_000_000_i32;
2122

@@ -261,7 +262,7 @@ impl Tm {
261262
priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
262263
fn match_str(s: &str, pos: uint, needle: &str) -> bool {
263264
let mut i = pos;
264-
for str::each(needle) |ch| {
265+
for needle.bytes_iter().advance |ch| {
265266
if s[i] != ch {
266267
return false;
267268
}

src/libextra/treemap.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,6 @@ mod test_set {
10341034

10351035
use super::*;
10361036

1037-
use core::vec;
1038-
10391037
#[test]
10401038
fn test_clear() {
10411039
let mut s = TreeSet::new();

src/libextra/uv_ll.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,6 @@ mod test {
12341234

12351235
use core::comm::{SharedChan, stream, GenericChan, GenericPort};
12361236
use core::libc;
1237-
use core::result;
12381237
use core::str;
12391238
use core::sys;
12401239
use core::task;

src/librustc/back/link.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use middle::trans::common::CrateContext;
2222
use middle::ty;
2323
use util::ppaux;
2424

25+
use core::iterator::IteratorUtil;
2526
use core::char;
2627
use core::hash::Streaming;
2728
use core::hash;
@@ -636,7 +637,7 @@ pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
636637
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
637638
pub fn sanitize(s: &str) -> ~str {
638639
let mut result = ~"";
639-
for str::each_char(s) |c| {
640+
for s.iter().advance |c| {
640641
match c {
641642
// Escape these with $ sequences
642643
'@' => result += "$SP$",

src/librustc/front/test.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
2222
use syntax::codemap;
2323
use syntax::ext::base::ExtCtxt;
2424
use syntax::fold;
25-
use syntax::parse::token;
2625
use syntax::print::pprust;
2726
use syntax::{ast, ast_util};
2827

0 commit comments

Comments
 (0)