sum_tree: Utilize size_hint
in TreeSet::extend
(#34936)
Collect the iterator instead of manually looping over it to utilize possible size hints. Zed usually passes in owned `Vec`'s, meaning we get to reuse memory as well. Release Notes: - N/A
This commit is contained in:
parent
6122f46095
commit
7db110f48d
1 changed files with 4 additions and 4 deletions
|
@ -71,10 +71,10 @@ impl<K: Clone + Ord, V: Clone> TreeMap<K, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>) {
|
pub fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>) {
|
||||||
let mut edits = Vec::new();
|
let edits: Vec<_> = iter
|
||||||
for (key, value) in iter {
|
.into_iter()
|
||||||
edits.push(Edit::Insert(MapEntry { key, value }));
|
.map(|(key, value)| Edit::Insert(MapEntry { key, value }))
|
||||||
}
|
.collect();
|
||||||
self.0.edit(edits, &());
|
self.0.edit(edits, &());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue