Skip to content

Commit

Permalink
Auto merge of #88282 - Neutron3529:patch-4, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Optimize BinaryHeap::extend from Vec

This improves the performance of extending `BinaryHeap`s from vectors directly. Future work may involve extending this optimization to other, similar, cases where the length of the added elements is well-known, but this is not yet done in this PR.
  • Loading branch information
bors committed Nov 14, 2021
2 parents c8e9497 + 2feee36 commit ad44239
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,14 @@ impl<T: Ord, I: IntoIterator<Item = T>> SpecExtend<I> for BinaryHeap<T> {
}
}

impl<T: Ord> SpecExtend<Vec<T>> for BinaryHeap<T> {
fn spec_extend(&mut self, ref mut other: Vec<T>) {
let start = self.data.len();
self.data.append(other);
self.rebuild_tail(start);
}
}

impl<T: Ord> SpecExtend<BinaryHeap<T>> for BinaryHeap<T> {
fn spec_extend(&mut self, ref mut other: BinaryHeap<T>) {
self.append(other);
Expand Down

0 comments on commit ad44239

Please sign in to comment.