From 86760f76acaf803a6204b6e76cab0957e92de6c2 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sun, 20 Mar 2022 13:50:04 +0000 Subject: [PATCH] Move resize to a more sensible place --- agb/src/hash_map.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index f3b221cc..bdb63cad 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -215,6 +215,18 @@ impl NodeStorage { 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> @@ -255,15 +267,7 @@ impl HashMap { 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); } }