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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 3 deletions
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
| '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '='

0 commit comments

Comments
 (0)