Skip to content

Commit 6dfcf9a

Browse files
committed
Remove branches from sift_down_to_bottom loop
1 parent dc06a36 commit 6dfcf9a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

library/alloc/src/collections/binary_heap.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,14 @@ impl<T: Ord> BinaryHeap<T> {
563563
unsafe {
564564
let mut hole = Hole::new(&mut self.data, pos);
565565
let mut child = 2 * pos + 1;
566-
while child < end {
567-
let right = child + 1;
568-
// compare with the greater of the two children
569-
if right < end && hole.get(child) <= hole.get(right) {
570-
child = right;
571-
}
566+
while child < end - 1 {
567+
child += (hole.get(child) <= hole.get(child + 1)) as usize;
572568
hole.move_to(child);
573569
child = 2 * hole.pos() + 1;
574570
}
571+
if child == end - 1 {
572+
hole.move_to(child);
573+
}
575574
pos = hole.pos;
576575
}
577576
self.sift_up(start, pos);

0 commit comments

Comments
 (0)