Skip to content

Commit ad44239

Browse files
committed
Auto merge of #88282 - Neutron3529:patch-4, r=Mark-Simulacrum
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.
2 parents c8e9497 + 2feee36 commit ad44239

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/alloc/src/collections/binary_heap.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,14 @@ impl<T: Ord, I: IntoIterator<Item = T>> SpecExtend<I> for BinaryHeap<T> {
15841584
}
15851585
}
15861586

1587+
impl<T: Ord> SpecExtend<Vec<T>> for BinaryHeap<T> {
1588+
fn spec_extend(&mut self, ref mut other: Vec<T>) {
1589+
let start = self.data.len();
1590+
self.data.append(other);
1591+
self.rebuild_tail(start);
1592+
}
1593+
}
1594+
15871595
impl<T: Ord> SpecExtend<BinaryHeap<T>> for BinaryHeap<T> {
15881596
fn spec_extend(&mut self, ref mut other: BinaryHeap<T>) {
15891597
self.append(other);

0 commit comments

Comments
 (0)