Explain why we use if/else control flow rather than match
This commit is contained in:
parent
7d078cfb94
commit
385ad48b35
@ -2163,6 +2163,10 @@ impl<T> [T] {
|
||||
// - `mid >= 0`
|
||||
// - `mid < size`: `mid` is limited by `[left; right)` bound.
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user