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> {
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
You can’t perform that action at this time.
0 commit comments