Skip to content

Commit a45fedf

Browse files
committedApr 4, 2017
simplify implementation of [T]::splitn and friends #41020
1 parent 2e3f0d8 commit a45fedf

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed
 

‎src/libcore/slice/mod.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ impl<T> SliceExt for [T] {
315315
SplitN {
316316
inner: GenericSplitN {
317317
iter: self.split(pred),
318-
count: n,
319-
invert: false
318+
count: n
320319
}
321320
}
322321
}
@@ -327,9 +326,8 @@ impl<T> SliceExt for [T] {
327326
{
328327
RSplitN {
329328
inner: GenericSplitN {
330-
iter: self.split(pred),
331-
count: n,
332-
invert: true
329+
iter: self.rsplit(pred),
330+
count: n
333331
}
334332
}
335333
}
@@ -504,8 +502,7 @@ impl<T> SliceExt for [T] {
504502
SplitNMut {
505503
inner: GenericSplitN {
506504
iter: self.split_mut(pred),
507-
count: n,
508-
invert: false
505+
count: n
509506
}
510507
}
511508
}
@@ -516,9 +513,8 @@ impl<T> SliceExt for [T] {
516513
{
517514
RSplitNMut {
518515
inner: GenericSplitN {
519-
iter: self.split_mut(pred),
520-
count: n,
521-
invert: true
516+
iter: self.rsplit_mut(pred),
517+
count: n
522518
}
523519
}
524520
}
@@ -1881,7 +1877,6 @@ impl<'a, T, P> FusedIterator for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool
18811877
struct GenericSplitN<I> {
18821878
iter: I,
18831879
count: usize,
1884-
invert: bool
18851880
}
18861881

18871882
impl<T, I: SplitIter<Item=T>> Iterator for GenericSplitN<I> {
@@ -1892,10 +1887,7 @@ impl<T, I: SplitIter<Item=T>> Iterator for GenericSplitN<I> {
18921887
match self.count {
18931888
0 => None,
18941889
1 => { self.count -= 1; self.iter.finish() }
1895-
_ => {
1896-
self.count -= 1;
1897-
if self.invert {self.iter.next_back()} else {self.iter.next()}
1898-
}
1890+
_ => { self.count -= 1; self.iter.next() }
18991891
}
19001892
}
19011893

@@ -1937,7 +1929,7 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitN<'a, T, P> where P: FnMut(&
19371929
/// [slices]: ../../std/primitive.slice.html
19381930
#[stable(feature = "rust1", since = "1.0.0")]
19391931
pub struct RSplitN<'a, T: 'a, P> where P: FnMut(&T) -> bool {
1940-
inner: GenericSplitN<Split<'a, T, P>>
1932+
inner: GenericSplitN<RSplit<'a, T, P>>
19411933
}
19421934

19431935
#[stable(feature = "core_impl_debug", since = "1.9.0")]
@@ -1980,7 +1972,7 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for SplitNMut<'a, T, P> where P: FnMu
19801972
/// [slices]: ../../std/primitive.slice.html
19811973
#[stable(feature = "rust1", since = "1.0.0")]
19821974
pub struct RSplitNMut<'a, T: 'a, P> where P: FnMut(&T) -> bool {
1983-
inner: GenericSplitN<SplitMut<'a, T, P>>
1975+
inner: GenericSplitN<RSplitMut<'a, T, P>>
19841976
}
19851977

19861978
#[stable(feature = "core_impl_debug", since = "1.9.0")]

0 commit comments

Comments
 (0)
Please sign in to comment.