Reuse allocations in fixing closures

This commit is contained in:
Ayaz Hafiz 2022-08-13 10:38:53 -07:00
parent d19c9107b2
commit c0969e5ff8
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 32 additions and 19 deletions

View file

@ -140,6 +140,12 @@ impl<K: PartialEq, V> VecMap<K, V> {
cur_idx: 0,
}
}
/// Removes all key/value pairs from the map, without affecting its allocated capacity.
pub fn clear(&mut self) {
self.keys.clear();
self.values.clear();
}
}
impl<K: PartialEq, V> Extend<(K, V)> for VecMap<K, V> {

View file

@ -83,6 +83,11 @@ impl<T: PartialEq> VecSet<T> {
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
self.elements.iter_mut()
}
/// Removes all elements from the set, without affecting its allocated capacity.
pub fn clear(&mut self) {
self.elements.clear()
}
}
impl<A: Ord> Extend<A> for VecSet<A> {