@@ -19,7 +19,7 @@ use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
19
19
use clone:: Clone ;
20
20
use old_iter:: BaseIter ;
21
21
use old_iter;
22
- use iterator:: Iterator ;
22
+ use iterator:: { Iterator , IteratorUtil } ;
23
23
use iter:: FromIter ;
24
24
use kinds:: Copy ;
25
25
use libc;
@@ -1568,28 +1568,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
1568
1568
return !broke;
1569
1569
}
1570
1570
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
-
1593
1571
/// Like `each()`, but for the case where you have a vector that *may or may
1594
1572
/// not* have mutable contents.
1595
1573
#[ inline( always) ]
@@ -1620,24 +1598,6 @@ pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
1620
1598
return true ;
1621
1599
}
1622
1600
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
-
1641
1601
/**
1642
1602
* Iterates over a vector's elements in reverse
1643
1603
*
@@ -2700,23 +2660,23 @@ impl<A> old_iter::BaseIter<A> for @[A] {
2700
2660
impl < ' self , A > old_iter:: MutableIter < A > for & ' self mut [ A ] {
2701
2661
#[ inline( always) ]
2702
2662
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)
2704
2664
}
2705
2665
}
2706
2666
2707
2667
// FIXME(#4148): This should be redundant
2708
2668
impl < A > old_iter:: MutableIter < A > for ~[ A ] {
2709
2669
#[ inline( always) ]
2710
2670
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)
2712
2672
}
2713
2673
}
2714
2674
2715
2675
// FIXME(#4148): This should be redundant
2716
2676
impl < A > old_iter:: MutableIter < A > for @mut [ A ] {
2717
2677
#[ inline( always) ]
2718
2678
fn each_mut ( & mut self , blk : & fn ( v : & mut A ) -> bool ) -> bool {
2719
- each_mut ( * self , blk)
2679
+ self . mut_iter ( ) . advance ( blk)
2720
2680
}
2721
2681
}
2722
2682
@@ -2748,7 +2708,7 @@ impl<'self,A> old_iter::ExtendedIter<A> for &'self [A] {
2748
2708
impl < ' self , A > old_iter:: ExtendedMutableIter < A > for & ' self mut [ A ] {
2749
2709
#[ inline( always) ]
2750
2710
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 ) )
2752
2712
}
2753
2713
}
2754
2714
@@ -3608,16 +3568,13 @@ mod tests {
3608
3568
fn test_each_ret_len0 ( ) {
3609
3569
let mut a0 : [ int , .. 0 ] = [ ] ;
3610
3570
assert_eq ! ( each( a0, |_p| fail!( ) ) , true ) ;
3611
- assert_eq ! ( each_mut( a0, |_p| fail!( ) ) , true ) ;
3612
3571
}
3613
3572
3614
3573
#[ test]
3615
3574
fn test_each_ret_len1 ( ) {
3616
3575
let mut a1 = [ 17 ] ;
3617
3576
assert_eq ! ( each( a1, |_p| true ) , true ) ;
3618
- assert_eq ! ( each_mut( a1, |_p| true ) , true ) ;
3619
3577
assert_eq ! ( each( a1, |_p| false ) , false ) ;
3620
- assert_eq ! ( each_mut( a1, |_p| false ) , false ) ;
3621
3578
}
3622
3579
3623
3580
0 commit comments