Skip to content

Commit 5db13c5

Browse files
committed
Make partition_point to forward to binary_search_by
1 parent 3396a38 commit 5db13c5

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

library/core/src/slice/mod.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -3458,27 +3458,7 @@ impl<T> [T] {
34583458
where
34593459
P: FnMut(&T) -> bool,
34603460
{
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)
34823462
}
34833463
}
34843464

0 commit comments

Comments
 (0)