diff options
| author | VillSnow <vill.snow@gmail.com> | 2021-05-17 19:13:41 +0900 |
|---|---|---|
| committer | VillSnow <vill.snow@gmail.com> | 2021-05-17 19:13:41 +0900 |
| commit | 5db13c529c58948437535865eb6e3957e4b7bf58 (patch) | |
| tree | fea99374b21e9ca79ce263404921f5c2e6d7096f | |
| parent | 3396a383bb1d1fdad8ceeb74f16cf08e0bd62a1b (diff) | |
| download | rust-5db13c529c58948437535865eb6e3957e4b7bf58.tar.gz rust-5db13c529c58948437535865eb6e3957e4b7bf58.zip | |
Make partition_point to forward to binary_search_by
| -rw-r--r-- | library/core/src/slice/mod.rs | 22 |
1 files changed, 1 insertions, 21 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 0923175414e..7478b65da45 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -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) } } |
