]> git.lizzy.rs Git - rust.git/commitdiff
Update next() and size_hint() for MutSpliterIterator
authorPalmer Cox <p@lmercox.com>
Thu, 12 Dec 2013 01:51:22 +0000 (20:51 -0500)
committer“Palmer <pcox@intelligent.net>
Sat, 21 Dec 2013 01:40:16 +0000 (20:40 -0500)
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

index 17e961723cfdc45eb703419cb2bd778c1e3fa2d1..b03cef093504398e14f247b6ffee43da112d2efc 100644 (file)
@@ -2528,13 +2528,13 @@ fn next(&mut self) -> Option<&'a mut [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))
+        }
     }
 }
 
@@ -2547,10 +2547,7 @@ fn next_back(&mut self) -> Option<&'a mut [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 []);