File tree 1 file changed +4
-2
lines changed
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -1223,7 +1223,8 @@ macro_rules! iterator {
1223
1223
P : FnMut ( Self :: Item ) -> bool ,
1224
1224
{
1225
1225
// 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( ) ;
1227
1228
self . try_fold( 0 , move |i, x| {
1228
1229
if predicate( x) { Err ( i) }
1229
1230
else { Ok ( i + 1 ) }
@@ -1241,7 +1242,8 @@ macro_rules! iterator {
1241
1242
{
1242
1243
// No need for an overflow check here, because `ExactSizeIterator`
1243
1244
// 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( ) ;
1245
1247
self . try_rfold( n, move |i, x| {
1246
1248
let i = i - 1 ;
1247
1249
if predicate( x) { Err ( i) }
You can’t perform that action at this time.
0 commit comments