File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -1223,7 +1223,8 @@ macro_rules! iterator {
12231223 P : FnMut ( Self :: Item ) -> bool ,
12241224 {
12251225 // The addition might panic on overflow
1226- let n = self . len( ) ;
1226+ // Use the len of the slice to hint optimizer to remove result index bounds check.
1227+ let n = make_slice!( self . ptr, self . end) . len( ) ;
12271228 self . try_fold( 0 , move |i, x| {
12281229 if predicate( x) { Err ( i) }
12291230 else { Ok ( i + 1 ) }
@@ -1241,7 +1242,8 @@ macro_rules! iterator {
12411242 {
12421243 // No need for an overflow check here, because `ExactSizeIterator`
12431244 // implies that the number of elements fits into a `usize`.
1244- let n = self . len( ) ;
1245+ // Use the len of the slice to hint optimizer to remove result index bounds check.
1246+ let n = make_slice!( self . ptr, self . end) . len( ) ;
12451247 self . try_rfold( n, move |i, x| {
12461248 let i = i - 1 ;
12471249 if predicate( x) { Err ( i) }
You can’t perform that action at this time.
0 commit comments