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 10:57:57 +03:00 committed by GitHub
parent 6122f46095
commit 7db110f48d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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)>) {
let mut edits = Vec::new();
for (key, value) in iter {
edits.push(Edit::Insert(MapEntry { key, value }));
}
let edits: Vec<_> = iter
.into_iter()
.map(|(key, value)| Edit::Insert(MapEntry { key, value }))
.collect();
self.0.edit(edits, &());
}