@@ -24,7 +24,6 @@ use core::cmp::Ordering;
24
24
use core:: default:: Default ;
25
25
use core:: fmt;
26
26
use core:: iter:: { self , repeat, FromIterator , IntoIterator , RandomAccessIterator } ;
27
- use core:: marker;
28
27
use core:: mem;
29
28
use core:: num:: { Int , UnsignedInt } ;
30
29
use core:: ops:: { Index , IndexMut } ;
@@ -545,9 +544,7 @@ impl<T> VecDeque<T> {
545
544
IterMut {
546
545
tail : self . tail ,
547
546
head : self . head ,
548
- cap : self . cap ,
549
- ptr : * self . ptr ,
550
- marker : marker:: PhantomData ,
547
+ ring : unsafe { self . buffer_as_mut_slice ( ) } ,
551
548
}
552
549
}
553
550
@@ -1515,17 +1512,12 @@ impl<'a, T> RandomAccessIterator for Iter<'a, T> {
1515
1512
}
1516
1513
}
1517
1514
1518
- // FIXME This was implemented differently from Iter because of a problem
1519
- // with returning the mutable reference. I couldn't find a way to
1520
- // make the lifetime checker happy so, but there should be a way.
1521
1515
/// `VecDeque` mutable iterator.
1522
1516
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1523
1517
pub struct IterMut < ' a , T : ' a > {
1524
- ptr : * mut T ,
1518
+ ring : & ' a mut [ T ] ,
1525
1519
tail : usize ,
1526
1520
head : usize ,
1527
- cap : usize ,
1528
- marker : marker:: PhantomData < & ' a mut T > ,
1529
1521
}
1530
1522
1531
1523
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1538,16 +1530,17 @@ impl<'a, T> Iterator for IterMut<'a, T> {
1538
1530
return None ;
1539
1531
}
1540
1532
let tail = self . tail ;
1541
- self . tail = wrap_index ( self . tail + 1 , self . cap ) ;
1533
+ self . tail = wrap_index ( self . tail + 1 , self . ring . len ( ) ) ;
1542
1534
1543
1535
unsafe {
1544
- Some ( & mut * self . ptr . offset ( tail as isize ) )
1536
+ let elem = self . ring . get_unchecked_mut ( tail) ;
1537
+ Some ( & mut * ( elem as * mut _ ) )
1545
1538
}
1546
1539
}
1547
1540
1548
1541
#[ inline]
1549
1542
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1550
- let len = count ( self . tail , self . head , self . cap ) ;
1543
+ let len = count ( self . tail , self . head , self . ring . len ( ) ) ;
1551
1544
( len, Some ( len) )
1552
1545
}
1553
1546
}
@@ -1559,10 +1552,11 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
1559
1552
if self . tail == self . head {
1560
1553
return None ;
1561
1554
}
1562
- self . head = wrap_index ( self . head - 1 , self . cap ) ;
1555
+ self . head = wrap_index ( self . head - 1 , self . ring . len ( ) ) ;
1563
1556
1564
1557
unsafe {
1565
- Some ( & mut * self . ptr . offset ( self . head as isize ) )
1558
+ let elem = self . ring . get_unchecked_mut ( self . head ) ;
1559
+ Some ( & mut * ( elem as * mut _ ) )
1566
1560
}
1567
1561
}
1568
1562
}
0 commit comments