mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-07-02 17:31:16 -03:00
Optimize function calls by reducing inherit vars heap allocations and copies
* Convert `function_get_inherit_vars()` to return a reference to the (possibly) existing map, rather than a copy; * Preallocate and reuse a static (read-only) map for the (very) common case of no inherited vars; * Pass references to the inherit vars map around thereafter, never triggering the map copy (or even move) constructor. NB: If it turns out the reference is unsafe, we can switch the inherit vars to be a shared_ptr and return that instead.
This commit is contained in:
@@ -257,10 +257,12 @@ bool function_get_definition(const wcstring &name, wcstring &out_definition) {
|
||||
return func != NULL;
|
||||
}
|
||||
|
||||
std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name) {
|
||||
const std::map<wcstring, env_var_t> &function_get_inherit_vars(const wcstring &name) {
|
||||
static const std::map<wcstring, env_var_t> empty_inherit_vars;
|
||||
|
||||
scoped_rlock locker(functions_lock);
|
||||
const function_info_t *func = function_get(name);
|
||||
return func ? func->inherit_vars : std::map<wcstring, env_var_t>();
|
||||
return func ? func->inherit_vars : empty_inherit_vars;
|
||||
}
|
||||
|
||||
bool function_get_desc(const wcstring &name, wcstring &out_desc) {
|
||||
|
||||
Reference in New Issue
Block a user