From 1b0642fdd55336fa574fa7df1a02510b279d7eda Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Thu, 26 Nov 2020 10:01:14 +0000 Subject: [PATCH] dict: use HashMap::with_capacity in extract --- src/types/dict.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/dict.rs b/src/types/dict.rs index de0abc3f..abd03958 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -331,7 +331,7 @@ where { fn extract(ob: &'source PyAny) -> Result { let dict = ::try_from(ob)?; - let mut ret = HashMap::default(); + let mut ret = HashMap::with_capacity_and_hasher(dict.len(), S::default()); for (k, v) in dict.iter() { ret.insert(K::extract(k)?, V::extract(v)?); } @@ -392,7 +392,7 @@ mod hashbrown_hashmap_conversion { { fn extract(ob: &'source PyAny) -> Result { let dict = ::try_from(ob)?; - let mut ret = hashbrown::HashMap::default(); + let mut ret = hashbrown::HashMap::with_capacity_and_hasher(dict.len(), S::default()); for (k, v) in dict.iter() { ret.insert(K::extract(k)?, V::extract(v)?); }