ckb_util/
shrink_to_fit.rs

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