Skip to content

Commit efd6194

Browse files
Palmer Cox“Palmer
Palmer Cox
authored and
“Palmer
committed
Remove remainder field from MutChunkIter
This field is no longer necessary now that rust-lang#9629 is fixed since we can just access the length of the remaining slice directly.
1 parent 9d1de0b commit efd6194

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/libstd/vec.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,8 +2127,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
21272127
#[inline]
21282128
fn mut_chunks(self, chunk_size: uint) -> MutChunkIter<'a, T> {
21292129
assert!(chunk_size > 0);
2130-
let len = self.len();
2131-
MutChunkIter { v: self, chunk_size: chunk_size, remaining: len }
2130+
MutChunkIter { v: self, chunk_size: chunk_size }
21322131
}
21332132

21342133
fn mut_shift_ref(&mut self) -> &'a mut T {
@@ -2568,31 +2567,29 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplitIterator<'a, T> {
25682567
/// the remainder.
25692568
pub struct MutChunkIter<'a, T> {
25702569
priv v: &'a mut [T],
2571-
priv chunk_size: uint,
2572-
priv remaining: uint
2570+
priv chunk_size: uint
25732571
}
25742572

25752573
impl<'a, T> Iterator<&'a mut [T]> for MutChunkIter<'a, T> {
25762574
#[inline]
25772575
fn next(&mut self) -> Option<&'a mut [T]> {
2578-
if self.remaining == 0 {
2576+
if self.v.len() == 0 {
25792577
None
25802578
} else {
2581-
let sz = cmp::min(self.remaining, self.chunk_size);
2579+
let sz = cmp::min(self.v.len(), self.chunk_size);
25822580
let tmp = util::replace(&mut self.v, &mut []);
25832581
let (head, tail) = tmp.mut_split_at(sz);
25842582
self.v = tail;
2585-
self.remaining -= sz;
25862583
Some(head)
25872584
}
25882585
}
25892586

25902587
#[inline]
25912588
fn size_hint(&self) -> (uint, Option<uint>) {
2592-
if self.remaining == 0 {
2589+
if self.v.len() == 0 {
25932590
(0, Some(0))
25942591
} else {
2595-
let (n, rem) = self.remaining.div_rem(&self.chunk_size);
2592+
let (n, rem) = self.v.len().div_rem(&self.chunk_size);
25962593
let n = if rem > 0 { n + 1 } else { n };
25972594
(n, Some(n))
25982595
}
@@ -2602,15 +2599,15 @@ impl<'a, T> Iterator<&'a mut [T]> for MutChunkIter<'a, T> {
26022599
impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutChunkIter<'a, T> {
26032600
#[inline]
26042601
fn next_back(&mut self) -> Option<&'a mut [T]> {
2605-
if self.remaining == 0 {
2602+
if self.v.len() == 0 {
26062603
None
26072604
} else {
2608-
let remainder = self.remaining % self.chunk_size;
2605+
let remainder = self.v.len() % self.chunk_size;
26092606
let sz = if remainder != 0 { remainder } else { self.chunk_size };
26102607
let tmp = util::replace(&mut self.v, &mut []);
2611-
let (head, tail) = tmp.mut_split_at(self.remaining - sz);
2608+
let tmp_len = tmp.len();
2609+
let (head, tail) = tmp.mut_split_at(tmp_len - sz);
26122610
self.v = head;
2613-
self.remaining -= sz;
26142611
Some(tail)
26152612
}
26162613
}

0 commit comments

Comments
 (0)