std: remove each[i]_mut functions, in favour of iterators.
This commit is contained in:
parent
f661a15b2b
commit
54d914a9a9
@ -24,6 +24,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::str;
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
@ -173,7 +174,7 @@ pub fn sha1() -> @Sha1 {
|
||||
fn mk_result(st: &mut Sha1State) -> ~[u8] {
|
||||
if !(*st).computed { pad_msg(st); (*st).computed = true; }
|
||||
let mut rs: ~[u8] = ~[];
|
||||
for vec::each_mut((*st).h) |ptr_hpart| {
|
||||
for st.h.mut_iter().advance |ptr_hpart| {
|
||||
let hpart = *ptr_hpart;
|
||||
let a = (hpart >> 24u32 & 0xFFu32) as u8;
|
||||
let b = (hpart >> 16u32 & 0xFFu32) as u8;
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::cast;
|
||||
use core::io;
|
||||
use core::str;
|
||||
@ -895,7 +896,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
|
||||
|
||||
fn reset(&mut self, bits: &mut [uint]) {
|
||||
let e = if self.dfcx.oper.initial_value() {uint::max_value} else {0};
|
||||
for vec::each_mut(bits) |b| { *b = e; }
|
||||
for bits.mut_iter().advance |b| { *b = e; }
|
||||
}
|
||||
|
||||
fn add_to_entry_set(&mut self, id: ast::node_id, pred_bits: &[uint]) {
|
||||
|
@ -87,6 +87,7 @@ bounded and unbounded protocols allows for less code duplication.
|
||||
use container::Container;
|
||||
use cast::{forget, transmute, transmute_copy};
|
||||
use either::{Either, Left, Right};
|
||||
use iterator::IteratorUtil;
|
||||
use kinds::Owned;
|
||||
use libc;
|
||||
use ops::Drop;
|
||||
@ -96,8 +97,7 @@ use unstable::intrinsics;
|
||||
use ptr;
|
||||
use ptr::RawPtr;
|
||||
use task;
|
||||
use vec;
|
||||
use vec::OwnedVector;
|
||||
use vec::{OwnedVector, MutableVector};
|
||||
use util::replace;
|
||||
|
||||
static SPIN_COUNT: uint = 0;
|
||||
@ -600,7 +600,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
|
||||
|
||||
let mut data_avail = false;
|
||||
let mut ready_packet = pkts.len();
|
||||
for vec::eachi_mut(pkts) |i, p| {
|
||||
for pkts.mut_iter().enumerate().advance |(i, p)| {
|
||||
unsafe {
|
||||
let p = &mut *p.header();
|
||||
let old = p.mark_blocked(this);
|
||||
@ -622,7 +622,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
|
||||
let event = wait_event(this) as *PacketHeader;
|
||||
|
||||
let mut pos = None;
|
||||
for vec::eachi_mut(pkts) |i, p| {
|
||||
for pkts.mut_iter().enumerate().advance |(i, p)| {
|
||||
if p.header() == event {
|
||||
pos = Some(i);
|
||||
break;
|
||||
@ -640,7 +640,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
|
||||
|
||||
debug!("%?", &mut pkts[ready_packet]);
|
||||
|
||||
for vec::each_mut(pkts) |p| {
|
||||
for pkts.mut_iter().advance |p| {
|
||||
unsafe {
|
||||
(*p.header()).unblock()
|
||||
}
|
||||
@ -853,7 +853,7 @@ pub fn select<T:Owned,Tb:Owned>(mut endpoints: ~[RecvPacketBuffered<T, Tb>])
|
||||
Option<T>,
|
||||
~[RecvPacketBuffered<T, Tb>]) {
|
||||
let mut endpoint_headers = ~[];
|
||||
for vec::each_mut(endpoints) |endpoint| {
|
||||
for endpoints.mut_iter().advance |endpoint| {
|
||||
endpoint_headers.push(endpoint.header());
|
||||
}
|
||||
|
||||
|
@ -82,4 +82,3 @@ pub use io::{Reader, ReaderUtil, Writer, WriterUtil};
|
||||
// Reexported runtime types
|
||||
pub use comm::{stream, Port, Chan, GenericChan, GenericSmartChan, GenericPort, Peekable};
|
||||
pub use task::spawn;
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
//! An ordered map and set for integer keys implemented as a radix trie
|
||||
|
||||
use prelude::*;
|
||||
use iterator::IteratorUtil;
|
||||
use uint;
|
||||
use util::{swap, replace};
|
||||
use vec;
|
||||
@ -277,7 +278,7 @@ impl<T> TrieNode<T> {
|
||||
}
|
||||
|
||||
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
|
||||
for vec::each_mut(self.children) |child| {
|
||||
for self.children.mut_iter().advance |child| {
|
||||
match *child {
|
||||
Internal(ref mut x) => if !x.mutate_values(f) {
|
||||
return false
|
||||
|
@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||
use clone::Clone;
|
||||
use old_iter::BaseIter;
|
||||
use old_iter;
|
||||
use iterator::Iterator;
|
||||
use iterator::{Iterator, IteratorUtil};
|
||||
use iter::FromIter;
|
||||
use kinds::Copy;
|
||||
use libc;
|
||||
@ -1568,28 +1568,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
|
||||
return !broke;
|
||||
}
|
||||
|
||||
/// Like `each()`, but for the case where you have
|
||||
/// a vector with mutable contents and you would like
|
||||
/// to mutate the contents as you iterate.
|
||||
#[inline(always)]
|
||||
pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool {
|
||||
let mut broke = false;
|
||||
do as_mut_buf(v) |p, n| {
|
||||
let mut n = n;
|
||||
let mut p = p;
|
||||
while n > 0 {
|
||||
unsafe {
|
||||
let q: &'r mut T = cast::transmute_mut_region(&mut *p);
|
||||
if !f(q) { break; }
|
||||
p = p.offset(1);
|
||||
}
|
||||
n -= 1;
|
||||
}
|
||||
broke = n > 0;
|
||||
}
|
||||
return !broke;
|
||||
}
|
||||
|
||||
/// Like `each()`, but for the case where you have a vector that *may or may
|
||||
/// not* have mutable contents.
|
||||
#[inline(always)]
|
||||
@ -1620,24 +1598,6 @@ pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over a mutable vector's elements and indices
|
||||
*
|
||||
* Return true to continue, false to break.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn eachi_mut<'r,T>(v: &'r mut [T],
|
||||
f: &fn(uint, v: &'r mut T) -> bool) -> bool {
|
||||
let mut i = 0;
|
||||
for each_mut(v) |p| {
|
||||
if !f(i, p) {
|
||||
return false;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over a vector's elements in reverse
|
||||
*
|
||||
@ -2700,7 +2660,7 @@ impl<A> old_iter::BaseIter<A> for @[A] {
|
||||
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) -> bool {
|
||||
each_mut(*self, blk)
|
||||
self.mut_iter().advance(blk)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2708,7 +2668,7 @@ impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
|
||||
impl<A> old_iter::MutableIter<A> for ~[A] {
|
||||
#[inline(always)]
|
||||
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) -> bool {
|
||||
each_mut(*self, blk)
|
||||
self.mut_iter().advance(blk)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2716,7 +2676,7 @@ impl<A> old_iter::MutableIter<A> for ~[A] {
|
||||
impl<A> old_iter::MutableIter<A> for @mut [A] {
|
||||
#[inline(always)]
|
||||
fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) -> bool {
|
||||
each_mut(*self, blk)
|
||||
self.mut_iter().advance(blk)
|
||||
}
|
||||
}
|
||||
|
||||
@ -2748,7 +2708,7 @@ impl<'self,A> old_iter::ExtendedIter<A> for &'self [A] {
|
||||
impl<'self,A> old_iter::ExtendedMutableIter<A> for &'self mut [A] {
|
||||
#[inline(always)]
|
||||
pub fn eachi_mut(&mut self, blk: &fn(uint, v: &mut A) -> bool) -> bool {
|
||||
eachi_mut(*self, blk)
|
||||
self.mut_iter().enumerate().advance(|(i, v)| blk(i, v))
|
||||
}
|
||||
}
|
||||
|
||||
@ -3608,16 +3568,13 @@ mod tests {
|
||||
fn test_each_ret_len0() {
|
||||
let mut a0 : [int, .. 0] = [];
|
||||
assert_eq!(each(a0, |_p| fail!()), true);
|
||||
assert_eq!(each_mut(a0, |_p| fail!()), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_each_ret_len1() {
|
||||
let mut a1 = [17];
|
||||
assert_eq!(each(a1, |_p| true), true);
|
||||
assert_eq!(each_mut(a1, |_p| true), true);
|
||||
assert_eq!(each(a1, |_p| false), false);
|
||||
assert_eq!(each_mut(a1, |_p| false), false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ use ext::quote::rt::*;
|
||||
use opt_vec;
|
||||
use opt_vec::OptVec;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::str;
|
||||
use core::vec;
|
||||
|
||||
@ -258,8 +259,7 @@ impl to_type_decls for state {
|
||||
let mut items = ~[];
|
||||
|
||||
{
|
||||
let messages = &mut *self.messages;
|
||||
for vec::each_mut(*messages) |m| {
|
||||
for self.messages.mut_iter().advance |m| {
|
||||
if dir == send {
|
||||
items.push(m.gen_send(cx, true));
|
||||
items.push(m.gen_send(cx, false));
|
||||
|
@ -22,6 +22,7 @@ use parse::parser::Parser;
|
||||
use parse::token::{Token, EOF, to_str, nonterminal, get_ident_interner, ident_to_str};
|
||||
use parse::token;
|
||||
|
||||
use core::iterator::IteratorUtil;
|
||||
use core::hashmap::HashMap;
|
||||
use core::str;
|
||||
use core::uint;
|
||||
@ -358,7 +359,7 @@ pub fn parse(
|
||||
if tok == EOF {
|
||||
if eof_eis.len() == 1u {
|
||||
let mut v = ~[];
|
||||
for vec::each_mut(eof_eis[0u].matches) |dv| {
|
||||
for eof_eis[0u].matches.mut_iter().advance |dv| {
|
||||
v.push(dv.pop());
|
||||
}
|
||||
return success(nameize(sess, ms, v));
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::iterator::IteratorUtil;
|
||||
use std::cast::transmute;
|
||||
use std::from_str::FromStr;
|
||||
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
|
||||
@ -134,7 +135,7 @@ impl RandomFasta {
|
||||
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
|
||||
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
|
||||
let mut j = 0;
|
||||
for vec::eachi_mut(lookup) |i, slot| {
|
||||
for lookup.mut_iter().enumerate().advance |(i, slot)| {
|
||||
while a[j].p < (i as f32) {
|
||||
j += 1;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::iterator::IteratorUtil;
|
||||
use std::f64;
|
||||
use std::from_str::FromStr;
|
||||
use std::os;
|
||||
@ -104,7 +105,7 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
|
||||
}
|
||||
}
|
||||
|
||||
for vec::each_mut(*bodies) |a| {
|
||||
for bodies.mut_iter().advance |a| {
|
||||
a.x[0] += dt * a.v[0];
|
||||
a.x[1] += dt * a.v[1];
|
||||
a.x[2] += dt * a.v[2];
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::iterator::IteratorUtil;
|
||||
use std::f64;
|
||||
use std::from_str::FromStr;
|
||||
use std::iter::ExtendedMutableIter;
|
||||
@ -18,9 +19,9 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
|
||||
}
|
||||
|
||||
fn mult_Av(v: &mut [f64], out: &mut [f64]) {
|
||||
for vec::eachi_mut(out) |i, out_i| {
|
||||
for out.mut_iter().enumerate().advance |(i, out_i)| {
|
||||
let mut sum = 0.0;
|
||||
for vec::eachi_mut(v) |j, &v_j| {
|
||||
for v.mut_iter().enumerate().advance |(j, &v_j)| {
|
||||
sum += v_j / (A(i as i32, j as i32) as f64);
|
||||
}
|
||||
*out_i = sum;
|
||||
@ -28,9 +29,9 @@ fn mult_Av(v: &mut [f64], out: &mut [f64]) {
|
||||
}
|
||||
|
||||
fn mult_Atv(v: &mut [f64], out: &mut [f64]) {
|
||||
for vec::eachi_mut(out) |i, out_i| {
|
||||
for out.mut_iter().enumerate().advance |(i, out_i)| {
|
||||
let mut sum = 0.0;
|
||||
for vec::eachi_mut(v) |j, &v_j| {
|
||||
for v.mut_iter().enumerate().advance |(j, &v_j)| {
|
||||
sum += v_j / (A(j as i32, i as i32) as f64);
|
||||
}
|
||||
*out_i = sum;
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::vec;
|
||||
use std::iterator::IteratorUtil;
|
||||
|
||||
fn test1() {
|
||||
let mut ints = [0, ..32];
|
||||
@ -18,7 +18,7 @@ fn test1() {
|
||||
|
||||
fn test2() {
|
||||
let mut ints = [0, ..32];
|
||||
for vec::each_mut(ints) |i| { *i += 22; }
|
||||
for ints.mut_iter().advance |i| { *i += 22; }
|
||||
for ints.each |i| { assert!(*i == 22); }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user