perf: Reduce alloc calls when building

Inspired by #4774
This commit is contained in:
Ed Page 2023-03-18 11:59:01 -05:00
parent 79b44d0460
commit a62fd05d53

View file

@ -126,6 +126,8 @@ impl MKeyMap {
/// We need a lazy build here since some we may change args after creating
/// the map, you can checkout who uses `args_mut`.
pub(crate) fn _build(&mut self) {
// There will be at least as many keys as args, so that is a good starting point
self.keys.reserve(self.args.len());
for (i, arg) in self.args.iter().enumerate() {
append_keys(&mut self.keys, arg, i);
}