Skip to content

Commit

Permalink
auto merge of #7566 : huonw/rust/vec-kill, r=cmr
Browse files Browse the repository at this point in the history
The last remaining internal iterator in `vec` is `each_permutation`.
  • Loading branch information
bors committed Jul 3, 2013
2 parents 1cee9d4 + cdea73c commit 0c6fc46
Show file tree
Hide file tree
Showing 58 changed files with 817 additions and 1,197 deletions.
2 changes: 1 addition & 1 deletion doc/tutorial-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Iterator<int> for ZeroStream {
## Container iterators
Containers implement iteration over the contained elements by returning an
iterator object. For example, vectors have four iterators available:
iterator object. For example, vector slices have four iterators available:
* `vector.iter()`, for immutable references to the elements
* `vector.mut_iter()`, for mutable references to the elements
Expand Down
5 changes: 2 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,8 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) ->
ProcArgs {
// If we've got another tool to run under (valgrind),
// then split apart its command
let toolargs = split_maybe_args(&config.runtool);

let mut args = toolargs + [make_exe_name(config, testfile).to_str()];
let mut args = split_maybe_args(&config.runtool);
args.push(make_exe_name(config, testfile).to_str());
let prog = args.shift();
return ProcArgs {prog: prog, args: args};
}
Expand Down
5 changes: 2 additions & 3 deletions src/libextra/crypto/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ impl Digest for Sha1 {

#[cfg(test)]
mod tests {
use std::vec;

use digest::{Digest, DigestUtil};
use sha1::Sha1;
Expand Down Expand Up @@ -337,7 +336,7 @@ mod tests {
for tests.iter().advance |t| {
(*sh).input_str(t.input);
sh.result(out);
assert!(vec::eq(t.output, out));
assert!(t.output.as_slice() == out);

let out_str = (*sh).result_str();
assert_eq!(out_str.len(), 40);
Expand All @@ -357,7 +356,7 @@ mod tests {
left = left - take;
}
sh.result(out);
assert!(vec::eq(t.output, out));
assert!(t.output.as_slice() == out);

let out_str = (*sh).result_str();
assert_eq!(out_str.len(), 40);
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal"
static LZ_BEST : c_int = 0xfff; // LZ with 4095 probes, "best"

pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
do vec::as_imm_buf(bytes) |b, len| {
do bytes.as_imm_buf |b, len| {
unsafe {
let mut outsz : size_t = 0;
let res =
Expand All @@ -63,7 +63,7 @@ pub fn deflate_bytes(bytes: &[u8]) -> ~[u8] {
}

pub fn inflate_bytes(bytes: &[u8]) -> ~[u8] {
do vec::as_imm_buf(bytes) |b, len| {
do bytes.as_imm_buf |b, len| {
unsafe {
let mut outsz : size_t = 0;
let res =
Expand Down
7 changes: 3 additions & 4 deletions src/libextra/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ use std::io;
use std::comm::GenericChan;
use std::comm::GenericPort;
use std::sys::size_of;
use std::vec;

/**
A FlatPort, consisting of a `BytePort` that receives byte vectors,
Expand Down Expand Up @@ -274,7 +273,7 @@ impl<T,U:Unflattener<T>,P:BytePort> GenericPort<T> for FlatPort<T, U, P> {
}
};

if vec::eq(command, CONTINUE) {
if CONTINUE.as_slice() == command {
let msg_len = match self.byte_port.try_recv(size_of::<u64>()) {
Some(bytes) => {
io::u64_from_be_bytes(bytes, 0, size_of::<u64>())
Expand Down Expand Up @@ -931,7 +930,7 @@ mod test {
fn test_try_recv_none3<P:BytePort>(loader: PortLoader<P>) {
static CONTINUE: [u8, ..4] = [0xAA, 0xBB, 0xCC, 0xDD];
// The control word is followed by garbage
let bytes = CONTINUE.to_owned() + [0];
let bytes = CONTINUE.to_owned() + &[0u8];
let port = loader(bytes);
let res: Option<int> = port.try_recv();
assert!(res.is_none());
Expand All @@ -955,7 +954,7 @@ mod test {
1, sys::size_of::<u64>()) |len_bytes| {
len_bytes.to_owned()
};
let bytes = CONTINUE.to_owned() + len_bytes + [0, 0, 0, 0];
let bytes = CONTINUE.to_owned() + len_bytes + &[0u8, 0, 0, 0];

let port = loader(bytes);

Expand Down
5 changes: 2 additions & 3 deletions src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::io::{WriterUtil, ReaderUtil};
use std::io;
use std::str;
use std::to_str;
use std::vec;

use serialize::Encodable;
use serialize;
Expand Down Expand Up @@ -941,7 +940,7 @@ impl serialize::Decoder for Decoder {
let name = match self.stack.pop() {
String(s) => s,
List(list) => {
do vec::consume_reverse(list) |_i, v| {
for list.consume_rev_iter().advance |v| {
self.stack.push(v);
}
match self.stack.pop() {
Expand Down Expand Up @@ -1059,7 +1058,7 @@ impl serialize::Decoder for Decoder {
let len = match self.stack.pop() {
List(list) => {
let len = list.len();
do vec::consume_reverse(list) |_i, v| {
for list.consume_rev_iter().advance |v| {
self.stack.push(v);
}
len
Expand Down
37 changes: 20 additions & 17 deletions src/libextra/num/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl Add<BigUint, BigUint> for BigUint {
let new_len = uint::max(self.data.len(), other.data.len());

let mut carry = 0;
let sum = do vec::from_fn(new_len) |i| {
let mut sum = do vec::from_fn(new_len) |i| {
let ai = if i < self.data.len() { self.data[i] } else { 0 };
let bi = if i < other.data.len() { other.data[i] } else { 0 };
let (hi, lo) = BigDigit::from_uint(
Expand All @@ -216,8 +216,8 @@ impl Add<BigUint, BigUint> for BigUint {
carry = hi;
lo
};
if carry == 0 { return BigUint::new(sum) };
return BigUint::new(sum + [carry]);
if carry != 0 { sum.push(carry); }
return BigUint::new(sum);
}
}

Expand Down Expand Up @@ -284,15 +284,15 @@ impl Mul<BigUint, BigUint> for BigUint {
if n == 1 { return copy *a; }

let mut carry = 0;
let prod = do a.data.iter().transform |ai| {
let mut prod = do a.data.iter().transform |ai| {
let (hi, lo) = BigDigit::from_uint(
(*ai as uint) * (n as uint) + (carry as uint)
);
carry = hi;
lo
}.collect::<~[BigDigit]>();
if carry == 0 { return BigUint::new(prod) };
return BigUint::new(prod + [carry]);
if carry != 0 { prod.push(carry); }
return BigUint::new(prod);
}


Expand Down Expand Up @@ -520,10 +520,12 @@ impl ToStrRadix for BigUint {

fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
if v.is_empty() { return ~"0" }
let s = vec::reversed(v).map(|n| {
let s = uint::to_str_radix(*n as uint, radix);
str::from_chars(vec::from_elem(l - s.len(), '0')) + s
}).concat();
let mut s = str::with_capacity(v.len() * l);
for v.rev_iter().advance |n| {
let ss = uint::to_str_radix(*n as uint, radix);
s.push_str("0".repeat(l - ss.len()));
s.push_str(ss);
}
s.trim_left_chars(&'0').to_owned()
}
}
Expand Down Expand Up @@ -619,15 +621,15 @@ impl BigUint {
if n_bits == 0 || self.is_zero() { return copy *self; }

let mut carry = 0;
let shifted = do self.data.iter().transform |elem| {
let mut shifted = do self.data.iter().transform |elem| {
let (hi, lo) = BigDigit::from_uint(
(*elem as uint) << n_bits | (carry as uint)
);
carry = hi;
lo
}.collect::<~[BigDigit]>();
if carry == 0 { return BigUint::new(shifted); }
return BigUint::new(shifted + [carry]);
if carry != 0 { shifted.push(carry); }
return BigUint::new(shifted);
}


Expand Down Expand Up @@ -1629,7 +1631,6 @@ mod bigint_tests {
use std::int;
use std::num::{IntConvertible, Zero, One, FromStrRadix};
use std::uint;
use std::vec;

#[test]
fn test_from_biguint() {
Expand All @@ -1646,9 +1647,11 @@ mod bigint_tests {

#[test]
fn test_cmp() {
let vs = [ &[2], &[1, 1], &[2, 1], &[1, 1, 1] ];
let mut nums = vec::reversed(vs)
.map(|s| BigInt::from_slice(Minus, *s));
let vs = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ];
let mut nums = ~[];
for vs.rev_iter().advance |s| {
nums.push(BigInt::from_slice(Minus, *s));
}
nums.push(Zero::zero());
nums.push_all_move(vs.map(|s| BigInt::from_slice(Plus, *s)));

Expand Down
7 changes: 3 additions & 4 deletions src/libextra/par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn map_slices<A:Copy + Send,B:Copy + Send>(
info!("spawning tasks");
while base < len {
let end = uint::min(len, base + items_per_task);
do vec::as_imm_buf(xs) |p, _len| {
do xs.as_imm_buf |p, _len| {
let f = f();
let base = base;
let f = do future_spawn() || {
Expand All @@ -78,11 +78,10 @@ fn map_slices<A:Copy + Send,B:Copy + Send>(
info!("num_tasks: %?", (num_tasks, futures.len()));
assert_eq!(num_tasks, futures.len());

let r = do vec::map_consume(futures) |ys| {
do futures.consume_iter().transform |ys| {
let mut ys = ys;
ys.get()
};
r
}.collect()
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ fn run_tests(opts: &TestOpts,
}

// All benchmarks run at the end, in serial.
do vec::consume(filtered_benchs) |_, b| {
for filtered_benchs.consume_iter().advance |b| {
callback(TeWait(copy b.desc));
run_test(!opts.run_benchmarks, b, ch.clone());
let (test, result) = p.recv();
Expand Down Expand Up @@ -523,7 +523,7 @@ pub fn filter_tests(
} else { return option::None; }
}

vec::filter_map(filtered, |x| filter_fn(x, filter_str))
filtered.consume_iter().filter_map(|x| filter_fn(x, filter_str)).collect()
};

// Maybe pull out the ignored test and unignore them
Expand All @@ -541,7 +541,7 @@ pub fn filter_tests(
None
}
};
vec::filter_map(filtered, |x| filter(x))
filtered.consume_iter().filter_map(|x| filter(x)).collect()
};

// Sort the tests alphabetically
Expand Down Expand Up @@ -720,9 +720,9 @@ impl BenchHarness {
// Eliminate outliers
let med = samples.median();
let mad = samples.median_abs_dev();
let samples = do vec::filter(samples) |f| {
let samples = do samples.consume_iter().filter |f| {
num::abs(*f - med) <= 3.0 * mad
};
}.collect::<~[f64]>();

debug!("%u samples, median %f, MAD=%f, %u survived filter",
n_samples, med as float, mad as float,
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ pub unsafe fn ip4_name(src: &sockaddr_in) -> ~str {
// ipv4 addr max size: 15 + 1 trailing null byte
let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8];
do vec::as_imm_buf(dst) |dst_buf, size| {
do dst.as_imm_buf |dst_buf, size| {
rust_uv_ip4_name(to_unsafe_ptr(src),
dst_buf, size as libc::size_t);
// seems that checking the result of uv_ip4_name
Expand All @@ -1066,7 +1066,7 @@ pub unsafe fn ip6_name(src: &sockaddr_in6) -> ~str {
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8,
0u8,0u8,0u8,0u8,0u8,0u8];
do vec::as_imm_buf(dst) |dst_buf, size| {
do dst.as_imm_buf |dst_buf, size| {
let src_unsafe_ptr = to_unsafe_ptr(src);
let result = rust_uv_ip6_name(src_unsafe_ptr,
dst_buf, size as libc::size_t);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ pub fn link_args(sess: Session,
// Add all the link args for external crates.
do cstore::iter_crate_data(cstore) |crate_num, _| {
let link_args = csearch::get_link_args_for_crate(cstore, crate_num);
do vec::consume(link_args) |_, link_arg| {
for link_args.consume_iter().advance |link_arg| {
args.push(link_arg);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ pub fn build_configuration(sess: Session, argv0: @str, input: &input) ->
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
fn parse_cfgspecs(cfgspecs: ~[~str],
demitter: diagnostic::Emitter) -> ast::crate_cfg {
do vec::map_consume(cfgspecs) |s| {
do cfgspecs.consume_iter().transform |s| {
let sess = parse::new_parse_sess(Some(demitter));
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
}
}.collect()
}

pub enum input {
Expand Down
Loading

0 comments on commit 0c6fc46

Please sign in to comment.