Skip to content

Commit 2c539d4

Browse files
Palmer Cox“Palmer
Palmer Cox
authored and
“Palmer
committed
Update next() and size_hint() for MutSpliterIterator
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.
1 parent efd6194 commit 2c539d4

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/libstd/vec.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,13 +2528,13 @@ impl<'a, T> Iterator<&'a mut [T]> for MutSplitIterator<'a, T> {
25282528

25292529
#[inline]
25302530
fn size_hint(&self) -> (uint, Option<uint>) {
2531-
if self.finished { return (0, Some(0)) }
2532-
2533-
// if the predicate doesn't match anything, we yield one slice
2534-
// if it matches every element, we yield len+1 empty slices.
2535-
// FIXME #9629
2536-
//(1, Some(self.v.len() + 1))
2537-
(1, None)
2531+
if self.finished {
2532+
(0, Some(0))
2533+
} else {
2534+
// if the predicate doesn't match anything, we yield one slice
2535+
// if it matches every element, we yield len+1 empty slices.
2536+
(1, Some(self.v.len() + 1))
2537+
}
25382538
}
25392539
}
25402540

@@ -2547,10 +2547,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut [T]> for MutSplitIterator<'a, T> {
25472547
None => {
25482548
self.finished = true;
25492549
let tmp = util::replace(&mut self.v, &mut []);
2550-
let len = tmp.len();
2551-
let (head, tail) = tmp.mut_split_at(len);
2552-
self.v = tail;
2553-
Some(head)
2550+
Some(tmp)
25542551
}
25552552
Some(idx) => {
25562553
let tmp = util::replace(&mut self.v, &mut []);

0 commit comments

Comments
 (0)