Merge pull request #4779 from epage/reserve

perf: Reduce alloc calls when building
This commit is contained in:
Ed Page 2023-03-23 15:43:33 -05:00 committed by GitHub
commit f04ad2f38c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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);
}