From 2c539d4eecec3c63f878a3798e0ea4df79b46f19 Mon Sep 17 00:00:00 2001 From: Palmer Cox Date: Wed, 11 Dec 2013 20:51:22 -0500 Subject: [PATCH] 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 #9629 is fixed. --- src/libstd/vec.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 17e961723cfdc..b03cef0935043 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -2528,13 +2528,13 @@ impl<'a, T> Iterator<&'a mut [T]> for MutSplitIterator<'a, T> { #[inline] fn size_hint(&self) -> (uint, Option) { - 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)) + } } } @@ -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 []);