File tree 1 file changed +1
-21
lines changed
1 file changed +1
-21
lines changed Original file line number Diff line number Diff line change @@ -3458,27 +3458,7 @@ impl<T> [T] {
3458
3458
where
3459
3459
P : FnMut ( & T ) -> bool ,
3460
3460
{
3461
- let mut left = 0 ;
3462
- let mut right = self . len ( ) ;
3463
-
3464
- while left != right {
3465
- let mid = left + ( right - left) / 2 ;
3466
- // SAFETY: When `left < right`, `left <= mid < right`.
3467
- // Therefore `left` always increases and `right` always decreases,
3468
- // and either of them is selected. In both cases `left <= right` is
3469
- // satisfied. Therefore if `left < right` in a step, `left <= right`
3470
- // is satisfied in the next step. Therefore as long as `left != right`,
3471
- // `0 <= left < right <= len` is satisfied and if this case
3472
- // `0 <= mid < len` is satisfied too.
3473
- let value = unsafe { self . get_unchecked ( mid) } ;
3474
- if pred ( value) {
3475
- left = mid + 1 ;
3476
- } else {
3477
- right = mid;
3478
- }
3479
- }
3480
-
3481
- left
3461
+ self . binary_search_by ( |x| if pred ( x) { Less } else { Greater } ) . unwrap_or_else ( |i| i)
3482
3462
}
3483
3463
}
3484
3464
You can’t perform that action at this time.
0 commit comments