We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6dfcf9a commit 25b3f61Copy full SHA for 25b3f61
library/alloc/src/collections/binary_heap.rs
@@ -531,19 +531,19 @@ impl<T: Ord> BinaryHeap<T> {
531
unsafe {
532
let mut hole = Hole::new(&mut self.data, pos);
533
let mut child = 2 * pos + 1;
534
- while child < end {
535
- let right = child + 1;
+ while child < end - 1 {
536
// compare with the greater of the two children
537
- if right < end && hole.get(child) <= hole.get(right) {
538
- child = right;
539
- }
+ child += (hole.get(child) <= hole.get(child + 1)) as usize;
540
// if we are already in order, stop.
541
if hole.element() >= hole.get(child) {
542
- break;
+ return;
543
}
544
hole.move_to(child);
545
child = 2 * hole.pos() + 1;
546
+ if child == end - 1 && hole.element() < hole.get(child) {
+ hole.move_to(child);
+ }
547
548
549
0 commit comments