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.
This commit is contained in:
commit
ad44239975
1 changed files with 8 additions and 0 deletions
|
@ -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> {
|
impl<T: Ord> SpecExtend<BinaryHeap<T>> for BinaryHeap<T> {
|
||||||
fn spec_extend(&mut self, ref mut other: BinaryHeap<T>) {
|
fn spec_extend(&mut self, ref mut other: BinaryHeap<T>) {
|
||||||
self.append(other);
|
self.append(other);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue