Skip to content

Commit 25b3f61

Browse files
committed
Remove useless branches from sift_down_range loop
1 parent 6dfcf9a commit 25b3f61

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

library/alloc/src/collections/binary_heap.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,19 @@ impl<T: Ord> BinaryHeap<T> {
531531
unsafe {
532532
let mut hole = Hole::new(&mut self.data, pos);
533533
let mut child = 2 * pos + 1;
534-
while child < end {
535-
let right = child + 1;
534+
while child < end - 1 {
536535
// compare with the greater of the two children
537-
if right < end && hole.get(child) <= hole.get(right) {
538-
child = right;
539-
}
536+
child += (hole.get(child) <= hole.get(child + 1)) as usize;
540537
// if we are already in order, stop.
541538
if hole.element() >= hole.get(child) {
542-
break;
539+
return;
543540
}
544541
hole.move_to(child);
545542
child = 2 * hole.pos() + 1;
546543
}
544+
if child == end - 1 && hole.element() < hole.get(child) {
545+
hole.move_to(child);
546+
}
547547
}
548548
}
549549

0 commit comments

Comments
 (0)