Skip to content

Commit

Permalink
Merge pull request #4779 from epage/reserve
Browse files Browse the repository at this point in the history
perf: Reduce alloc calls when building
  • Loading branch information
epage authored Mar 23, 2023
2 parents bdfc6be + a62fd05 commit f04ad2f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mkeymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit f04ad2f

Please sign in to comment.