1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/// Shrinks the map `$map` when it reserves more than `$threhold` slots for future entries. /// /// ## Examples /// /// ``` /// use std::collections::HashMap; /// use ckb_util::shrink_to_fit; /// /// let mut h = HashMap::<u32, u32>::new(); /// // Shrink the map when it reserves more than 10 slots for future entries. /// shrink_to_fit!(h, 10); /// ``` #[macro_export] macro_rules! shrink_to_fit { ($map:expr, $threhold:expr) => {{ if $map.capacity() > ($map.len() + $threhold) { $map.shrink_to_fit(); } }}; }