Use HashMap::with_capacity instead of new+reserve

This commit is contained in:
Avery Winters 2024-01-15 11:21:55 -06:00
parent 2b6e344bc4
commit fb0654e263
Signed by: avery
SSH key fingerprint: SHA256:eesvLB5MMqHLZrAMFt6kEhqJWnASMLcET6Sgmw0FqZI

View file

@ -4,8 +4,7 @@ macro_rules! hashmap {
(@count $($expr:expr),*) => (<[()]>::len(&[$(hashmap!(@discard $expr)),*])); (@count $($expr:expr),*) => (<[()]>::len(&[$(hashmap!(@discard $expr)),*]));
($($($key:expr => $expr:expr),+ $(,)?)?) => {{ ($($($key:expr => $expr:expr),+ $(,)?)?) => {{
let cap = hashmap!(@count $($($key),*)?); let cap = hashmap!(@count $($($key),*)?);
let mut map = ::std::collections::HashMap::new(); let mut map = ::std::collections::HashMap::with_capacity(cap);
map.reserve(cap);
$($(map.insert($key, $expr);)*)? $($(map.insert($key, $expr);)*)?
map map
}}; }};