From a62fd05d5392fd48a5fe9347451a49d18f564ab0 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 18 Mar 2023 11:59:01 -0500 Subject: [PATCH] perf: Reduce alloc calls when building Inspired by #4774 --- src/mkeymap.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mkeymap.rs b/src/mkeymap.rs index a54fae45..e9d6ab84 100644 --- a/src/mkeymap.rs +++ b/src/mkeymap.rs @@ -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); }