File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
library/alloc/src/collections Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -531,19 +531,19 @@ impl<T: Ord> BinaryHeap<T> {
531
531
unsafe {
532
532
let mut hole = Hole :: new ( & mut self . data , pos) ;
533
533
let mut child = 2 * pos + 1 ;
534
- while child < end {
535
- let right = child + 1 ;
534
+ while child < end - 1 {
536
535
// 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 ;
540
537
// if we are already in order, stop.
541
538
if hole. element ( ) >= hole. get ( child) {
542
- break ;
539
+ return ;
543
540
}
544
541
hole. move_to ( child) ;
545
542
child = 2 * hole. pos ( ) + 1 ;
546
543
}
544
+ if child == end - 1 && hole. element ( ) < hole. get ( child) {
545
+ hole. move_to ( child) ;
546
+ }
547
547
}
548
548
}
549
549
You can’t perform that action at this time.
0 commit comments