Skip to content

Removing internal iterators from str & vec, part 2 #7015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ a single large vector of floats. Each task needs the full vector to perform its
# use std::vec;
# use std::uint;
# use std::rand;
# use std::iterator::IteratorUtil;
use extra::arc::ARC;

fn pnorm(nums: &~[float], p: uint) -> float {
(vec::foldl(0.0, *nums, |a,b| a+(*b).pow(p as float) )).pow(1f / (p as float))
nums.iter().fold(0.0, |a,b| a+(*b).pow(p as float) ).pow(1f / (p as float))
}

fn main() {
Expand Down
6 changes: 0 additions & 6 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@

use core::prelude::*;

use core::comm;
use core::io;
use core::libc::c_int;
use core::os;
use core::run;
use core::str;
use core::task;
use core::vec;

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

3 changes: 2 additions & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use procsrv;
use util;
use util::logv;

use core::iterator::IteratorUtil;
use core::io;
use core::os;
use core::str;
Expand Down Expand Up @@ -780,7 +781,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
Some(~""));

let mut exitcode : int = 0;
for str::each_char(exitcode_out) |c| {
for exitcode_out.iter().advance |c| {
if !c.is_digit() { break; }
exitcode = exitcode * 10 + match c {
'0' .. '9' => c as int - ('0' as int),
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::managed;
use core::old_iter;
use core::vec;
Expand Down Expand Up @@ -110,7 +111,7 @@ pub fn from_elem<T>(data: T) -> @mut DList<T> {

/// Creates a new dlist from a vector of elements, maintaining the same order
pub fn from_vec<T:Copy>(vec: &[T]) -> @mut DList<T> {
do vec::foldl(DList(), vec) |list,data| {
do vec.iter().fold(DList()) |list,data| {
list.push(*data); // Iterating left-to-right -- add newly to the tail.
list
}
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/fileinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ mod test {

use super::{FileInput, pathify, input_vec, input_vec_state};

use core::iterator::IteratorUtil;
use core::io;
use core::str;
use core::uint;
Expand Down Expand Up @@ -455,7 +456,7 @@ mod test {

let fi = FileInput::from_vec(copy filenames);

for "012".each_chari |line, c| {
for "012".iter().enumerate().advance |(line, c)| {
assert_eq!(fi.read_byte(), c as int);
assert_eq!(fi.state().line_num, line);
assert_eq!(fi.state().line_num_file, 0);
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Simple compression

#[allow(missing_doc)];

use core::prelude::*;

use core::libc::{c_void, size_t, c_int};
use core::libc;
use core::vec;
Expand Down Expand Up @@ -87,6 +85,7 @@ mod tests {
use super::*;
use core::rand;
use core::rand::RngUtil;
use core::prelude::*;

#[test]
#[allow(non_implicitly_copyable_typarams)]
Expand Down
1 change: 0 additions & 1 deletion src/libextra/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ mod test {
use core::int;
use core::io::BytesWriter;
use core::result;
use core::sys;
use core::task;

#[test]
Expand Down
6 changes: 4 additions & 2 deletions src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::char;
use core::float;
use core::hashmap::HashMap;
Expand Down Expand Up @@ -58,7 +59,7 @@ pub struct Error {

fn escape_str(s: &str) -> ~str {
let mut escaped = ~"\"";
for str::each_char(s) |c| {
for s.iter().advance |c| {
match c {
'"' => escaped += "\\\"",
'\\' => escaped += "\\\\",
Expand Down Expand Up @@ -913,7 +914,8 @@ impl serialize::Decoder for Decoder {

fn read_char(&mut self) -> char {
let mut v = ~[];
for str::each_char(self.read_str()) |c| { v.push(c) }
let s = self.read_str();
for s.iter().advance |c| { v.push(c) }
if v.len() != 1 { fail!("string must have one character") }
v[0]
}
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use core::prelude::*;

use core::vec;
use core::iterator::IteratorUtil;

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

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

/**
Expand Down
7 changes: 4 additions & 3 deletions src/libextra/net_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::cmp::Eq;
use core::io::{Reader, ReaderUtil};
use core::io;
Expand Down Expand Up @@ -358,7 +359,7 @@ pub fn query_to_str(query: &Query) -> ~str {

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

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

// deal with input class first
Expand Down Expand Up @@ -562,7 +563,7 @@ fn get_path(rawurl: &str, authority: bool) ->
Result<(~str, ~str), ~str> {
let len = str::len(rawurl);
let mut end = len;
for str::each_chari(rawurl) |i,c| {
for rawurl.iter().enumerate().advance |(i,c)| {
match c {
'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '&' |'\'' | '(' | ')' | '.'
| '@' | ':' | '%' | '/' | '+' | '!' | '*' | ',' | ';' | '='
Expand Down
15 changes: 6 additions & 9 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A BigInt is a combination of BigUint and Sign.
#[allow(missing_doc)];

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
use core::int;
use core::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable};
Expand Down Expand Up @@ -129,12 +129,9 @@ impl TotalOrd for BigUint {
if s_len < o_len { return Less; }
if s_len > o_len { return Greater; }

for self.data.eachi_reverse |i, elm| {
match (*elm, other.data[i]) {
(l, r) if l < r => return Less,
(l, r) if l > r => return Greater,
_ => loop
};
for self.data.rev_iter().zip(other.data.rev_iter()).advance |(&self_i, &other_i)| {
cond!((self_i < other_i) { return Less; }
(self_i > other_i) { return Greater; })
}
return Equal;
}
Expand Down Expand Up @@ -421,7 +418,7 @@ impl Integer for BigUint {
let bn = *b.data.last();
let mut d = ~[];
let mut carry = 0;
for an.each_reverse |elt| {
for an.rev_iter().advance |elt| {
let ai = BigDigit::to_uint(carry, *elt);
let di = ai / (bn as uint);
assert!(di < BigDigit::base);
Expand Down Expand Up @@ -648,7 +645,7 @@ impl BigUint {

let mut borrow = 0;
let mut shifted = ~[];
for self.data.each_reverse |elem| {
for self.data.rev_iter().advance |elem| {
shifted = ~[(*elem >> n_bits) | borrow] + shifted;
borrow = *elem << (BigDigit::bits - n_bits);
}
Expand Down
18 changes: 9 additions & 9 deletions src/libextra/par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use core::prelude::*;

use core::iterator::IteratorUtil;
use core::cast;
use core::ptr;
use core::sys;
Expand Down Expand Up @@ -122,25 +123,24 @@ pub fn alli<A:Copy + Owned>(
xs: &[A],
fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
{
do vec::all(map_slices(xs, || {
let mapped = map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> bool = |base, slice| {
vec::alli(slice, |i, x| {
f(i + base, x)
})
slice.iter().enumerate().all(|(i, x)| f(i + base, x))
};
result
})) |x| { *x }
});
mapped.iter().all(|&x| x)
}

/// Returns true if the function holds for any elements in the vector.
pub fn any<A:Copy + Owned>(
xs: &[A],
fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
do vec::any(map_slices(xs, || {
let mapped = map_slices(xs, || {
let f = fn_factory();
let result: ~fn(uint, &[A]) -> bool =
|_, slice| vec::any(slice, |x| f(x));
let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f);
result
})) |x| { *x }
});
mapped.iter().any(|&x| x)
}
3 changes: 0 additions & 3 deletions src/libextra/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,11 +929,8 @@ mod test_tim_sort {
use core::prelude::*;

use sort::tim_sort;

use core::local_data;
use core::rand::RngUtil;
use core::rand;
use core::uint;
use core::vec;

struct CVal {
Expand Down
7 changes: 4 additions & 3 deletions src/libextra/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use core::prelude::*;

use core::iterator::*;
use core::vec;
use core::f64;
use core::cmp;
Expand All @@ -36,17 +37,17 @@ pub trait Stats {

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

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

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

fn mean(self) -> f64 {
Expand Down
1 change: 0 additions & 1 deletion src/libextra/std.rc
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,3 @@ pub mod extra {
pub use serialize;
pub use test;
}

1 change: 0 additions & 1 deletion src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,6 @@ mod tests {
use core::cast;
use core::cell::Cell;
use core::comm;
use core::ptr;
use core::result;
use core::task;
use core::vec;
Expand Down
1 change: 0 additions & 1 deletion src/libextra/tempfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ mod tests {
use core::prelude::*;

use tempfile::mkdtemp;
use tempfile;

use core::os;
use core::str;
Expand Down
3 changes: 2 additions & 1 deletion src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use core::i32;
use core::int;
use core::io;
use core::str;
use core::iterator::IteratorUtil;

static NSEC_PER_SEC: i32 = 1_000_000_000_i32;

Expand Down Expand Up @@ -261,7 +262,7 @@ impl Tm {
priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
fn match_str(s: &str, pos: uint, needle: &str) -> bool {
let mut i = pos;
for str::each(needle) |ch| {
for needle.bytes_iter().advance |ch| {
if s[i] != ch {
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions src/libextra/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,6 @@ mod test_set {

use super::*;

use core::vec;

#[test]
fn test_clear() {
let mut s = TreeSet::new();
Expand Down
1 change: 0 additions & 1 deletion src/libextra/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,6 @@ mod test {

use core::comm::{SharedChan, stream, GenericChan, GenericPort};
use core::libc;
use core::result;
use core::str;
use core::sys;
use core::task;
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use middle::trans::common::CrateContext;
use middle::ty;
use util::ppaux;

use core::iterator::IteratorUtil;
use core::char;
use core::hash::Streaming;
use core::hash;
Expand Down Expand Up @@ -636,7 +637,7 @@ pub fn get_symbol_hash(ccx: @CrateContext, t: ty::t) -> @str {
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
pub fn sanitize(s: &str) -> ~str {
let mut result = ~"";
for str::each_char(s) |c| {
for s.iter().advance |c| {
match c {
// Escape these with $ sequences
'@' => result += "$SP$",
Expand Down
1 change: 0 additions & 1 deletion src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
use syntax::codemap;
use syntax::ext::base::ExtCtxt;
use syntax::fold;
use syntax::parse::token;
use syntax::print::pprust;
use syntax::{ast, ast_util};

Expand Down
Loading