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:
tidely
2025-07-23 09:57:57 +02:00
committed by GitHub
parent 6122f46095
commit 7db110f48d
+4 -4
View File
@@ -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, &());
} }