We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7e07219 commit ee0376cCopy full SHA for ee0376c
library/core/src/slice/sort.rs
@@ -198,7 +198,12 @@ where
198
}
199
200
// Choose the greater child.
201
- child += (child + 1 < v.len() && is_less(&v[child], &v[child + 1])) as usize;
+ if child + 1 < v.len() {
202
+ // We need a branch to be sure not to out-of-bounds index,
203
+ // but it's highly predictable. The comparison, however,
204
+ // is better done branchless, especially for primitives.
205
+ child += is_less(&v[child], &v[child + 1]) as usize;
206
+ }
207
208
// Stop if the invariant holds at `node`.
209
if !is_less(&v[node], &v[child]) {
0 commit comments