Skip to content

Commit

Permalink
cmd: pre-allocate the output Vec in get_command_values()
Browse files Browse the repository at this point in the history
  • Loading branch information
davvid committed Dec 23, 2023
1 parent 63b97af commit 63f4b7e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,11 @@ pub(crate) fn get_command_values(
context: &model::TreeContext,
name: &str,
) -> Vec<String> {
let mut commands = Vec::new();
let mut vec_variables = Vec::new();

let config = match context.config {
Some(config_id) => app_context.get_config(config_id),
None => app_context.get_root_config(),
};
let mut vec_variables = Vec::new();

// Global commands
for (command_name, var) in &config.commands {
Expand Down Expand Up @@ -218,6 +216,7 @@ pub(crate) fn get_command_values(
}
}

let mut commands = Vec::with_capacity(vec_variables.len() * 2);
for variables in vec_variables.iter_mut() {
let values = eval::variables_for_shell(app_context, config, variables, context);
commands.extend(values);
Expand Down

0 comments on commit 63f4b7e

Please sign in to comment.