Avoid an errant copy in autoload_t::resolve_command

The ternary expression was causing the list of paths (e.g.
$fish_function_path) to be copied. Avoid that copy with an if statement.

This reduces the time spent in try_autoload from 2.4 sec to 961ms on
the seq_echo benchmark run 1024 times, about 5% improvement.

Oh, C++...
This commit is contained in:
ridiculousfish 2020-08-07 22:16:09 -07:00
parent 2cd336376e
commit 5bee1e3e1f

View file

@ -165,8 +165,11 @@ wcstring_list_t autoload_t::get_autoloaded_commands() const {
}
maybe_t<wcstring> autoload_t::resolve_command(const wcstring &cmd, const environment_t &env) {
maybe_t<env_var_t> mvar = env.get(env_var_name_);
return resolve_command(cmd, mvar ? mvar->as_list() : wcstring_list_t{});
if (maybe_t<env_var_t> mvar = env.get(env_var_name_)) {
return resolve_command(cmd, mvar->as_list());
} else {
return resolve_command(cmd, wcstring_list_t{});
}
}
maybe_t<wcstring> autoload_t::resolve_command(const wcstring &cmd, const wcstring_list_t &paths) {