Make clear faster

This commit is contained in:
Gwilym Inzani 2023-05-10 18:13:32 +01:00
parent 943fd1154f
commit bb5bd04b5f
2 changed files with 8 additions and 2 deletions

View file

@ -254,8 +254,7 @@ impl<K, V, ALLOCATOR: ClonableAllocator> HashMap<K, V, ALLOCATOR> {
/// Removes all elements from the map
pub fn clear(&mut self) {
self.nodes =
NodeStorage::with_size_in(self.nodes.backing_vec_size(), self.allocator().clone());
self.nodes.clear();
}
/// An iterator visiting all key-value pairs in an arbitrary order

View file

@ -210,4 +210,11 @@ impl<K, V, ALLOCATOR: ClonableAllocator> NodeStorage<K, V, ALLOCATOR> {
(ret, self.max_distance_to_initial_bucket as usize)
}
pub(crate) fn clear(&mut self) {
self.max_distance_to_initial_bucket = 0;
self.number_of_items = 0;
self.nodes.fill_with(Node::new);
}
}