We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7d078cf commit 385ad48Copy full SHA for 385ad48
library/core/src/slice/mod.rs
@@ -2163,6 +2163,10 @@ impl<T> [T] {
2163
// - `mid >= 0`
2164
// - `mid < size`: `mid` is limited by `[left; right)` bound.
2165
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.
2170
if cmp == Less {
2171
left = mid + 1;
2172
} else if cmp == Greater {
0 commit comments