diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index df7fe2bf76dcd..c8987c7b4a88e 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -2481,17 +2481,14 @@ impl [T] { // we have `left + size/2 < self.len()`, and this is in-bounds. let cmp = f(unsafe { self.get_unchecked(mid) }); - // The reason why we use if/else control flow rather than match - // is because match reorders comparison operations, which is perf sensitive. - // This is x86 asm for u8: https://rust.godbolt.org/z/8Y8Pra. - if cmp == Less { - left = mid + 1; - } else if cmp == Greater { - right = mid; - } else { - // SAFETY: same as the `get_unchecked` above - unsafe { crate::intrinsics::assume(mid < self.len()) }; - return Ok(mid); + match cmp { + Ordering::Less => left = mid + 1, + Ordering::Greater => right = mid, + Ordering::Equal => { + // SAFETY: same as the `get_unchecked` above + unsafe { crate::intrinsics::assume(mid < self.len()) }; + return Ok(mid); + } } size = right - left;