mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-20 14:11:14 -03:00
Refactor function_get_[desc/definition] to pass-by-reference
This commit is contained in:
@@ -228,6 +228,7 @@ void function_remove(const wcstring &name) {
|
||||
if (function_remove_ignore_autoload(name)) function_autoloader.unload(name);
|
||||
}
|
||||
|
||||
/// Returns a function by name if it has been loaded, returns false otherwise. Does not autoload.
|
||||
static const function_info_t *function_get(const wcstring &name) {
|
||||
// The caller must lock the functions_lock before calling this; however our mutex is currently
|
||||
// recursive, so trylock will never fail. We need a way to correctly check if a lock is locked
|
||||
@@ -240,11 +241,11 @@ static const function_info_t *function_get(const wcstring &name) {
|
||||
return &iter->second;
|
||||
}
|
||||
|
||||
bool function_get_definition(const wcstring &name, wcstring *out_definition) {
|
||||
bool function_get_definition(const wcstring &name, wcstring &out_definition) {
|
||||
scoped_rlock locker(functions_lock);
|
||||
const function_info_t *func = function_get(name);
|
||||
if (func && out_definition) {
|
||||
out_definition->assign(func->props->body_node.get_source(func->props->parsed_source->src));
|
||||
if (func) {
|
||||
out_definition = func->props->body_node.get_source(func->props->parsed_source->src);
|
||||
}
|
||||
return func != NULL;
|
||||
}
|
||||
@@ -255,12 +256,12 @@ std::map<wcstring, env_var_t> function_get_inherit_vars(const wcstring &name) {
|
||||
return func ? func->inherit_vars : std::map<wcstring, env_var_t>();
|
||||
}
|
||||
|
||||
bool function_get_desc(const wcstring &name, wcstring *out_desc) {
|
||||
bool function_get_desc(const wcstring &name, wcstring &out_desc) {
|
||||
// Empty length string goes to NULL.
|
||||
scoped_rlock locker(functions_lock);
|
||||
const function_info_t *func = function_get(name);
|
||||
if (out_desc && func && !func->description.empty()) {
|
||||
out_desc->assign(_(func->description.c_str()));
|
||||
if (func && !func->description.empty()) {
|
||||
out_desc = _(func->description.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user