Skip to content

Commit 385ad48

Browse files
committed
Explain why we use if/else control flow rather than match
1 parent 7d078cf commit 385ad48

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

library/core/src/slice/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,10 @@ impl<T> [T] {
21632163
// - `mid >= 0`
21642164
// - `mid < size`: `mid` is limited by `[left; right)` bound.
21652165
let cmp = f(unsafe { self.get_unchecked(mid) });
2166+
2167+
// The reason why we use if/else control flow rather than match
2168+
// is because match reorders comparison operations, which is perf sensitive.
2169+
// This is x86 asm for u8: https://rust.godbolt.org/z/8Y8Pra.
21662170
if cmp == Less {
21672171
left = mid + 1;
21682172
} else if cmp == Greater {

0 commit comments

Comments
 (0)