about summary refs log tree commit diff
path: root/src/libcore/slice.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-04-01 11:28:34 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-04-01 13:29:42 -0700
commite98dce3e00a7b6bfd264418ef993bbf9cdb1f0b6 (patch)
tree1569b4aa8d412df9c49904b8bddeb44d8d4ecef2 /src/libcore/slice.rs
parentd528aa9960cb9b937d8ef6c09905a6a8076d5f3a (diff)
downloadrust-e98dce3e00a7b6bfd264418ef993bbf9cdb1f0b6.tar.gz
rust-e98dce3e00a7b6bfd264418ef993bbf9cdb1f0b6.zip
std: Changing the meaning of the count to splitn
This commit is an implementation of [RFC 979][rfc] which changes the meaning of
the count parameter to the `splitn` function on strings and slices. The
parameter now means the number of items that are returned from the iterator, not
the number of splits that are made.

[rfc]: https://github.com/rust-lang/rfcs/pull/979

Closes #23911
[breaking-change]
Diffstat (limited to 'src/libcore/slice.rs')
-rw-r--r--src/libcore/slice.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index d8856130fab..70e60adf64c 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -1126,18 +1126,20 @@ impl<T, I: SplitIter<Item=T>> Iterator for GenericSplitN<I> {
 
     #[inline]
     fn next(&mut self) -> Option<T> {
-        if self.count == 0 {
-            self.iter.finish()
-        } else {
-            self.count -= 1;
-            if self.invert { self.iter.next_back() } else { self.iter.next() }
+        match self.count {
+            0 => None,
+            1 => { self.count -= 1; self.iter.finish() }
+            _ => {
+                self.count -= 1;
+                if self.invert {self.iter.next_back()} else {self.iter.next()}
+            }
         }
     }
 
     #[inline]
     fn size_hint(&self) -> (usize, Option<usize>) {
         let (lower, upper_opt) = self.iter.size_hint();
-        (lower, upper_opt.map(|upper| cmp::min(self.count + 1, upper)))
+        (lower, upper_opt.map(|upper| cmp::min(self.count, upper)))
     }
 }