File tree 1 file changed +7
-13
lines changed
src/libcore/iter/adapters
1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -1801,17 +1801,15 @@ where
1801
1801
#[ inline]
1802
1802
fn nth ( & mut self , n : usize ) -> Option < I :: Item > {
1803
1803
// Can't just add n + self.n due to overflow.
1804
- if self . n == 0 {
1805
- self . iter . nth ( n)
1806
- } else {
1804
+ if self . n > 0 {
1807
1805
let to_skip = self . n ;
1808
1806
self . n = 0 ;
1809
1807
// nth(n) skips n+1
1810
1808
if self . iter . nth ( to_skip - 1 ) . is_none ( ) {
1811
1809
return None ;
1812
1810
}
1813
- self . iter . nth ( n)
1814
1811
}
1812
+ self . iter . nth ( n)
1815
1813
}
1816
1814
1817
1815
#[ inline]
@@ -1827,17 +1825,13 @@ where
1827
1825
1828
1826
#[ inline]
1829
1827
fn last ( mut self ) -> Option < I :: Item > {
1830
- if self . n == 0 {
1831
- self . iter . last ( )
1832
- } else {
1833
- let next = self . next ( ) ;
1834
- if next. is_some ( ) {
1835
- // recurse. n should be 0.
1836
- self . last ( ) . or ( next)
1837
- } else {
1838
- None
1828
+ if self . n > 0 {
1829
+ // nth(n) skips n+1
1830
+ if self . iter . nth ( self . n - 1 ) . is_none ( ) {
1831
+ return None ;
1839
1832
}
1840
1833
}
1834
+ self . iter . last ( )
1841
1835
}
1842
1836
1843
1837
#[ inline]
You can’t perform that action at this time.
0 commit comments