We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dc06a36 commit 6dfcf9aCopy full SHA for 6dfcf9a
library/alloc/src/collections/binary_heap.rs
@@ -563,15 +563,14 @@ impl<T: Ord> BinaryHeap<T> {
563
unsafe {
564
let mut hole = Hole::new(&mut self.data, pos);
565
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
- }
+ while child < end - 1 {
+ child += (hole.get(child) <= hole.get(child + 1)) as usize;
572
hole.move_to(child);
573
child = 2 * hole.pos() + 1;
574
}
+ if child == end - 1 {
+ hole.move_to(child);
+ }
575
pos = hole.pos;
576
577
self.sift_up(start, pos);
0 commit comments