Skip to content

Commit 54d914a

Browse files
committed
std: remove each[i]_mut functions, in favour of iterators.
1 parent f661a15 commit 54d914a

File tree

12 files changed

+32
-69
lines changed

12 files changed

+32
-69
lines changed

src/libextra/sha1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use core::prelude::*;
2626

27+
use core::iterator::IteratorUtil;
2728
use core::str;
2829
use core::uint;
2930
use core::vec;
@@ -173,7 +174,7 @@ pub fn sha1() -> @Sha1 {
173174
fn mk_result(st: &mut Sha1State) -> ~[u8] {
174175
if !(*st).computed { pad_msg(st); (*st).computed = true; }
175176
let mut rs: ~[u8] = ~[];
176-
for vec::each_mut((*st).h) |ptr_hpart| {
177+
for st.h.mut_iter().advance |ptr_hpart| {
177178
let hpart = *ptr_hpart;
178179
let a = (hpart >> 24u32 & 0xFFu32) as u8;
179180
let b = (hpart >> 16u32 & 0xFFu32) as u8;

src/librustc/middle/dataflow.rs

+2-1
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::cast;
2223
use core::io;
2324
use core::str;
@@ -895,7 +896,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
895896

896897
fn reset(&mut self, bits: &mut [uint]) {
897898
let e = if self.dfcx.oper.initial_value() {uint::max_value} else {0};
898-
for vec::each_mut(bits) |b| { *b = e; }
899+
for bits.mut_iter().advance |b| { *b = e; }
899900
}
900901

901902
fn add_to_entry_set(&mut self, id: ast::node_id, pred_bits: &[uint]) {

src/libstd/pipes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ bounded and unbounded protocols allows for less code duplication.
8787
use container::Container;
8888
use cast::{forget, transmute, transmute_copy};
8989
use either::{Either, Left, Right};
90+
use iterator::IteratorUtil;
9091
use kinds::Owned;
9192
use libc;
9293
use ops::Drop;
@@ -96,8 +97,7 @@ use unstable::intrinsics;
9697
use ptr;
9798
use ptr::RawPtr;
9899
use task;
99-
use vec;
100-
use vec::OwnedVector;
100+
use vec::{OwnedVector, MutableVector};
101101
use util::replace;
102102

103103
static SPIN_COUNT: uint = 0;
@@ -600,7 +600,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
600600

601601
let mut data_avail = false;
602602
let mut ready_packet = pkts.len();
603-
for vec::eachi_mut(pkts) |i, p| {
603+
for pkts.mut_iter().enumerate().advance |(i, p)| {
604604
unsafe {
605605
let p = &mut *p.header();
606606
let old = p.mark_blocked(this);
@@ -622,7 +622,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
622622
let event = wait_event(this) as *PacketHeader;
623623

624624
let mut pos = None;
625-
for vec::eachi_mut(pkts) |i, p| {
625+
for pkts.mut_iter().enumerate().advance |(i, p)| {
626626
if p.header() == event {
627627
pos = Some(i);
628628
break;
@@ -640,7 +640,7 @@ pub fn wait_many<T: Selectable>(pkts: &mut [T]) -> uint {
640640

641641
debug!("%?", &mut pkts[ready_packet]);
642642

643-
for vec::each_mut(pkts) |p| {
643+
for pkts.mut_iter().advance |p| {
644644
unsafe {
645645
(*p.header()).unblock()
646646
}
@@ -853,7 +853,7 @@ pub fn select<T:Owned,Tb:Owned>(mut endpoints: ~[RecvPacketBuffered<T, Tb>])
853853
Option<T>,
854854
~[RecvPacketBuffered<T, Tb>]) {
855855
let mut endpoint_headers = ~[];
856-
for vec::each_mut(endpoints) |endpoint| {
856+
for endpoints.mut_iter().advance |endpoint| {
857857
endpoint_headers.push(endpoint.header());
858858
}
859859

src/libstd/prelude.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,3 @@ pub use io::{Reader, ReaderUtil, Writer, WriterUtil};
8282
// Reexported runtime types
8383
pub use comm::{stream, Port, Chan, GenericChan, GenericSmartChan, GenericPort, Peekable};
8484
pub use task::spawn;
85-

src/libstd/trie.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//! An ordered map and set for integer keys implemented as a radix trie
1212
1313
use prelude::*;
14+
use iterator::IteratorUtil;
1415
use uint;
1516
use util::{swap, replace};
1617
use vec;
@@ -277,7 +278,7 @@ impl<T> TrieNode<T> {
277278
}
278279

279280
fn mutate_values<'a>(&'a mut self, f: &fn(&uint, &mut T) -> bool) -> bool {
280-
for vec::each_mut(self.children) |child| {
281+
for self.children.mut_iter().advance |child| {
281282
match *child {
282283
Internal(ref mut x) => if !x.mutate_values(f) {
283284
return false

src/libstd/vec.rs

+5-48
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
1919
use clone::Clone;
2020
use old_iter::BaseIter;
2121
use old_iter;
22-
use iterator::Iterator;
22+
use iterator::{Iterator, IteratorUtil};
2323
use iter::FromIter;
2424
use kinds::Copy;
2525
use libc;
@@ -1568,28 +1568,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
15681568
return !broke;
15691569
}
15701570

1571-
/// Like `each()`, but for the case where you have
1572-
/// a vector with mutable contents and you would like
1573-
/// to mutate the contents as you iterate.
1574-
#[inline(always)]
1575-
pub fn each_mut<'r,T>(v: &'r mut [T], f: &fn(elem: &'r mut T) -> bool) -> bool {
1576-
let mut broke = false;
1577-
do as_mut_buf(v) |p, n| {
1578-
let mut n = n;
1579-
let mut p = p;
1580-
while n > 0 {
1581-
unsafe {
1582-
let q: &'r mut T = cast::transmute_mut_region(&mut *p);
1583-
if !f(q) { break; }
1584-
p = p.offset(1);
1585-
}
1586-
n -= 1;
1587-
}
1588-
broke = n > 0;
1589-
}
1590-
return !broke;
1591-
}
1592-
15931571
/// Like `each()`, but for the case where you have a vector that *may or may
15941572
/// not* have mutable contents.
15951573
#[inline(always)]
@@ -1620,24 +1598,6 @@ pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
16201598
return true;
16211599
}
16221600

1623-
/**
1624-
* Iterates over a mutable vector's elements and indices
1625-
*
1626-
* Return true to continue, false to break.
1627-
*/
1628-
#[inline(always)]
1629-
pub fn eachi_mut<'r,T>(v: &'r mut [T],
1630-
f: &fn(uint, v: &'r mut T) -> bool) -> bool {
1631-
let mut i = 0;
1632-
for each_mut(v) |p| {
1633-
if !f(i, p) {
1634-
return false;
1635-
}
1636-
i += 1;
1637-
}
1638-
return true;
1639-
}
1640-
16411601
/**
16421602
* Iterates over a vector's elements in reverse
16431603
*
@@ -2700,23 +2660,23 @@ impl<A> old_iter::BaseIter<A> for @[A] {
27002660
impl<'self,A> old_iter::MutableIter<A> for &'self mut [A] {
27012661
#[inline(always)]
27022662
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) -> bool {
2703-
each_mut(*self, blk)
2663+
self.mut_iter().advance(blk)
27042664
}
27052665
}
27062666

27072667
// FIXME(#4148): This should be redundant
27082668
impl<A> old_iter::MutableIter<A> for ~[A] {
27092669
#[inline(always)]
27102670
fn each_mut<'a>(&'a mut self, blk: &fn(v: &'a mut A) -> bool) -> bool {
2711-
each_mut(*self, blk)
2671+
self.mut_iter().advance(blk)
27122672
}
27132673
}
27142674

27152675
// FIXME(#4148): This should be redundant
27162676
impl<A> old_iter::MutableIter<A> for @mut [A] {
27172677
#[inline(always)]
27182678
fn each_mut(&mut self, blk: &fn(v: &mut A) -> bool) -> bool {
2719-
each_mut(*self, blk)
2679+
self.mut_iter().advance(blk)
27202680
}
27212681
}
27222682

@@ -2748,7 +2708,7 @@ impl<'self,A> old_iter::ExtendedIter<A> for &'self [A] {
27482708
impl<'self,A> old_iter::ExtendedMutableIter<A> for &'self mut [A] {
27492709
#[inline(always)]
27502710
pub fn eachi_mut(&mut self, blk: &fn(uint, v: &mut A) -> bool) -> bool {
2751-
eachi_mut(*self, blk)
2711+
self.mut_iter().enumerate().advance(|(i, v)| blk(i, v))
27522712
}
27532713
}
27542714

@@ -3608,16 +3568,13 @@ mod tests {
36083568
fn test_each_ret_len0() {
36093569
let mut a0 : [int, .. 0] = [];
36103570
assert_eq!(each(a0, |_p| fail!()), true);
3611-
assert_eq!(each_mut(a0, |_p| fail!()), true);
36123571
}
36133572

36143573
#[test]
36153574
fn test_each_ret_len1() {
36163575
let mut a1 = [17];
36173576
assert_eq!(each(a1, |_p| true), true);
3618-
assert_eq!(each_mut(a1, |_p| true), true);
36193577
assert_eq!(each(a1, |_p| false), false);
3620-
assert_eq!(each_mut(a1, |_p| false), false);
36213578
}
36223579

36233580

src/libsyntax/ext/pipes/pipec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use ext::quote::rt::*;
2323
use opt_vec;
2424
use opt_vec::OptVec;
2525

26+
use core::iterator::IteratorUtil;
2627
use core::str;
2728
use core::vec;
2829

@@ -258,8 +259,7 @@ impl to_type_decls for state {
258259
let mut items = ~[];
259260
260261
{
261-
let messages = &mut *self.messages;
262-
for vec::each_mut(*messages) |m| {
262+
for self.messages.mut_iter().advance |m| {
263263
if dir == send {
264264
items.push(m.gen_send(cx, true));
265265
items.push(m.gen_send(cx, false));

src/libsyntax/ext/tt/macro_parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use parse::parser::Parser;
2222
use parse::token::{Token, EOF, to_str, nonterminal, get_ident_interner, ident_to_str};
2323
use parse::token;
2424

25+
use core::iterator::IteratorUtil;
2526
use core::hashmap::HashMap;
2627
use core::str;
2728
use core::uint;
@@ -358,7 +359,7 @@ pub fn parse(
358359
if tok == EOF {
359360
if eof_eis.len() == 1u {
360361
let mut v = ~[];
361-
for vec::each_mut(eof_eis[0u].matches) |dv| {
362+
for eof_eis[0u].matches.mut_iter().advance |dv| {
362363
v.push(dv.pop());
363364
}
364365
return success(nameize(sess, ms, v));

src/test/bench/shootout-fasta-redux.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::iterator::IteratorUtil;
12
use std::cast::transmute;
23
use std::from_str::FromStr;
34
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
@@ -134,7 +135,7 @@ impl RandomFasta {
134135
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
135136
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
136137
let mut j = 0;
137-
for vec::eachi_mut(lookup) |i, slot| {
138+
for lookup.mut_iter().enumerate().advance |(i, slot)| {
138139
while a[j].p < (i as f32) {
139140
j += 1;
140141
}

src/test/bench/shootout-nbody.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::iterator::IteratorUtil;
12
use std::f64;
23
use std::from_str::FromStr;
34
use std::os;
@@ -104,7 +105,7 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) {
104105
}
105106
}
106107

107-
for vec::each_mut(*bodies) |a| {
108+
for bodies.mut_iter().advance |a| {
108109
a.x[0] += dt * a.v[0];
109110
a.x[1] += dt * a.v[1];
110111
a.x[2] += dt * a.v[2];

src/test/bench/shootout-spectralnorm.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::iterator::IteratorUtil;
12
use std::f64;
23
use std::from_str::FromStr;
34
use std::iter::ExtendedMutableIter;
@@ -18,19 +19,19 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
1819
}
1920

2021
fn mult_Av(v: &mut [f64], out: &mut [f64]) {
21-
for vec::eachi_mut(out) |i, out_i| {
22+
for out.mut_iter().enumerate().advance |(i, out_i)| {
2223
let mut sum = 0.0;
23-
for vec::eachi_mut(v) |j, &v_j| {
24+
for v.mut_iter().enumerate().advance |(j, &v_j)| {
2425
sum += v_j / (A(i as i32, j as i32) as f64);
2526
}
2627
*out_i = sum;
2728
}
2829
}
2930

3031
fn mult_Atv(v: &mut [f64], out: &mut [f64]) {
31-
for vec::eachi_mut(out) |i, out_i| {
32+
for out.mut_iter().enumerate().advance |(i, out_i)| {
3233
let mut sum = 0.0;
33-
for vec::eachi_mut(v) |j, &v_j| {
34+
for v.mut_iter().enumerate().advance |(j, &v_j)| {
3435
sum += v_j / (A(j as i32, i as i32) as f64);
3536
}
3637
*out_i = sum;

src/test/run-pass/mutability-inherits-through-fixed-length-vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::vec;
11+
use std::iterator::IteratorUtil;
1212

1313
fn test1() {
1414
let mut ints = [0, ..32];
@@ -18,7 +18,7 @@ fn test1() {
1818

1919
fn test2() {
2020
let mut ints = [0, ..32];
21-
for vec::each_mut(ints) |i| { *i += 22; }
21+
for ints.mut_iter().advance |i| { *i += 22; }
2222
for ints.each |i| { assert!(*i == 22); }
2323
}
2424

0 commit comments

Comments
 (0)