Skip to content

Commit e43d6fb

Browse files
committed
Move cmp back to loop
1 parent cb6b585 commit e43d6fb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

library/core/src/slice/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,6 @@ impl<T> [T] {
27832783
}
27842784
let mut base = 0usize;
27852785

2786-
let mut cmp:Ordering = Equal;
27872786
// This loop intentionally doesn't have an early exit if the comparison
27882787
// returns Equal. We want the number of loop iterations to depend *only*
27892788
// on the size of the input slice so that the CPU can reliably predict
@@ -2796,7 +2795,7 @@ impl<T> [T] {
27962795
// SAFETY: the call is made safe by the following inconstants:
27972796
// - `mid >= 0`: by definition
27982797
// - `mid < size`: `mid = size / 2 + size / 4 + size / 8 ...`
2799-
cmp = f(unsafe { self.get_unchecked(mid) });
2798+
let cmp = f(unsafe { self.get_unchecked(mid) });
28002799

28012800
// Binary search interacts poorly with branch prediction, so force
28022801
// the compiler to use conditional moves if supported by the target

0 commit comments

Comments
 (0)