Skip to content

Commit

Permalink
Update next() and size_hint() for MutSpliterIterator
Browse files Browse the repository at this point in the history
Update the next() method to just return self.v in the case that we've reached
the last element that the iterator will yield. This produces equivalent
behavior as before, but without the cost of updating the field.

Update the size_hint() method to return a better hint now that rust-lang#9629 is fixed.
  • Loading branch information
Palmer Cox authored and “Palmer committed Dec 21, 2013
1 parent efd6194 commit 2c539d4
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2528,13 +2528,13 @@ impl<'a, T> Iterator<&'a mut [T]> for MutSplitIterator<'a, T> {

#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
if self.finished { return (0, Some(0)) }

// if the predicate doesn't match anything, we yield one slice
// if it matches every element, we yield len+1 empty slices.
// FIXME #9629
//(1, Some(self.v.len() + 1))
(1, None)
if self.finished {
(0, Some(0))
} else {
// if the predicate doesn't match anything, we yield one slice
// if it matches every element, we yield len+1 empty slices.
(1, Some(self.v.len() + 1))
}
}
}

Expand All @@ -2547,10 +2547,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplitIterator<'a, T> {
None => {
self.finished = true;
let tmp = util::replace(&mut self.v, &mut []);
let len = tmp.len();
let (head, tail) = tmp.mut_split_at(len);
self.v = tail;
Some(head)
Some(tmp)
}
Some(idx) => {
let tmp = util::replace(&mut self.v, &mut []);
Expand Down

0 comments on commit 2c539d4

Please sign in to comment.