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 @@ -1890,17 +1890,15 @@ where
1890
1890
#[ inline]
1891
1891
fn nth ( & mut self , n : usize ) -> Option < I :: Item > {
1892
1892
// Can't just add n + self.n due to overflow.
1893
- if self . n == 0 {
1894
- self . iter . nth ( n)
1895
- } else {
1893
+ if self . n > 0 {
1896
1894
let to_skip = self . n ;
1897
1895
self . n = 0 ;
1898
1896
// nth(n) skips n+1
1899
1897
if self . iter . nth ( to_skip - 1 ) . is_none ( ) {
1900
1898
return None ;
1901
1899
}
1902
- self . iter . nth ( n)
1903
1900
}
1901
+ self . iter . nth ( n)
1904
1902
}
1905
1903
1906
1904
#[ inline]
@@ -1916,17 +1914,13 @@ where
1916
1914
1917
1915
#[ inline]
1918
1916
fn last ( mut self ) -> Option < I :: Item > {
1919
- if self . n == 0 {
1920
- self . iter . last ( )
1921
- } else {
1922
- let next = self . next ( ) ;
1923
- if next. is_some ( ) {
1924
- // recurse. n should be 0.
1925
- self . last ( ) . or ( next)
1926
- } else {
1927
- None
1917
+ if self . n > 0 {
1918
+ // nth(n) skips n+1
1919
+ if self . iter . nth ( self . n - 1 ) . is_none ( ) {
1920
+ return None ;
1928
1921
}
1929
1922
}
1923
+ self . iter . last ( )
1930
1924
}
1931
1925
1932
1926
#[ inline]
You can’t perform that action at this time.
0 commit comments