Move resize to a more sensible place

This commit is contained in:
Gwilym Kuiper 2022-03-20 13:50:04 +00:00
parent e9c56327b1
commit 86760f76ac

View file

@ -215,6 +215,18 @@ impl<K, V> NodeStorage<K, V> {
None
}
fn resized_to(&mut self, new_size: usize) -> Self {
let mut new_node_storage = Self::with_size(new_size);
for mut node in self.nodes.drain(..) {
if let Some((key, value, hash)) = node.take_key_value() {
new_node_storage.insert_new(key, value, hash);
}
}
new_node_storage
}
}
pub struct HashMap<K, V, H = BuildHasherDefault<FxHasher>>
@ -255,15 +267,7 @@ impl<K, V> HashMap<K, V> {
return;
}
let mut new_node_storage = NodeStorage::with_size(new_size);
for mut node in self.nodes.nodes.drain(..) {
if let Some((key, value, hash)) = node.take_key_value() {
new_node_storage.insert_new(key, value, hash);
}
}
self.nodes = new_node_storage;
self.nodes = self.nodes.resized_to(new_size);
}
}