From 5bee1e3e1f4b9227044d699083d98653fb227fbb Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 7 Aug 2020 22:16:09 -0700 Subject: [PATCH] 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++... --- src/autoload.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/autoload.cpp b/src/autoload.cpp index 7661c15f2..81bd5f5d2 100644 --- a/src/autoload.cpp +++ b/src/autoload.cpp @@ -165,8 +165,11 @@ wcstring_list_t autoload_t::get_autoloaded_commands() const { } maybe_t autoload_t::resolve_command(const wcstring &cmd, const environment_t &env) { - maybe_t mvar = env.get(env_var_name_); - return resolve_command(cmd, mvar ? mvar->as_list() : wcstring_list_t{}); + if (maybe_t mvar = env.get(env_var_name_)) { + return resolve_command(cmd, mvar->as_list()); + } else { + return resolve_command(cmd, wcstring_list_t{}); + } } maybe_t autoload_t::resolve_command(const wcstring &cmd, const wcstring_list_t &paths) {