Skip to content

Commit

Permalink
Make partition_point to forward to binary_search_by
Browse files Browse the repository at this point in the history
  • Loading branch information
VillSnow committed May 17, 2021
1 parent 3396a38 commit 5db13c5
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3458,27 +3458,7 @@ impl<T> [T] {
where
P: FnMut(&T) -> bool,
{
let mut left = 0;
let mut right = self.len();

while left != right {
let mid = left + (right - left) / 2;
// SAFETY: When `left < right`, `left <= mid < right`.
// Therefore `left` always increases and `right` always decreases,
// and either of them is selected. In both cases `left <= right` is
// satisfied. Therefore if `left < right` in a step, `left <= right`
// is satisfied in the next step. Therefore as long as `left != right`,
// `0 <= left < right <= len` is satisfied and if this case
// `0 <= mid < len` is satisfied too.
let value = unsafe { self.get_unchecked(mid) };
if pred(value) {
left = mid + 1;
} else {
right = mid;
}
}

left
self.binary_search_by(|x| if pred(x) { Less } else { Greater }).unwrap_or_else(|i| i)
}
}

Expand Down

0 comments on commit 5db13c5

Please sign in to comment.