diff options
| author | bors <bors@rust-lang.org> | 2021-11-14 18:47:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-11-14 18:47:42 +0000 |
| commit | ad442399756573dccacb314b6bf8079964bcc72a (patch) | |
| tree | 6ef7324d0a4bb040207c7d32dcdb69280ce579b9 | |
| parent | c8e94975a6541e947a1bd4971e084c8ba637f2b6 (diff) | |
| parent | 2feee3659e19fddf2eb47ea37293cae73bd52c98 (diff) | |
| download | rust-ad442399756573dccacb314b6bf8079964bcc72a.tar.gz rust-ad442399756573dccacb314b6bf8079964bcc72a.zip | |
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.
| -rw-r--r-- | library/alloc/src/collections/binary_heap.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 7fb7686a6e2..7d87974b47e 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -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); |
