Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove useless branches from sift_down_range loop
  • Loading branch information
SkiFire13 committed Nov 7, 2020
commit 25b3f61c3821fd597961f9dd394482b71600e859
12 changes: 6 additions & 6 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,19 @@ impl<T: Ord> BinaryHeap<T> {
unsafe {
let mut hole = Hole::new(&mut self.data, pos);
let mut child = 2 * pos + 1;
while child < end {
let right = child + 1;
while child < end - 1 {
// compare with the greater of the two children
if right < end && hole.get(child) <= hole.get(right) {
child = right;
}
child += (hole.get(child) <= hole.get(child + 1)) as usize;
// if we are already in order, stop.
if hole.element() >= hole.get(child) {
break;
return;
}
hole.move_to(child);
child = 2 * hole.pos() + 1;
}
if child == end - 1 && hole.element() < hole.get(child) {
hole.move_to(child);
}
}
}

Expand Down