about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--library/core/src/slice/mod.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index c7dd000f71f..bc3f02efdda 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -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 {