File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,7 @@ use fmt;
307
307
use iter_private:: TrustedRandomAccess ;
308
308
use ops:: Try ;
309
309
use usize;
310
+ use intrinsics;
310
311
311
312
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
312
313
pub use self :: iterator:: Iterator ;
@@ -718,7 +719,11 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
718
719
}
719
720
720
721
// overflow handling
721
- while n. checked_mul ( step) . is_none ( ) {
722
+ loop {
723
+ let mul = n. checked_mul ( step) ;
724
+ if unsafe { intrinsics:: likely ( mul. is_some ( ) ) } {
725
+ return self . iter . nth ( mul. unwrap ( ) - 1 ) ;
726
+ }
722
727
let div_n = usize:: MAX / n;
723
728
let div_step = usize:: MAX / step;
724
729
let nth_n = div_n * n;
@@ -732,7 +737,6 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
732
737
} ;
733
738
self . iter . nth ( nth - 1 ) ;
734
739
}
735
- self . iter . nth ( n * step - 1 )
736
740
}
737
741
}
738
742
You can’t perform that action at this time.
0 commit comments