Refactor function_get_[desc/definition] to pass-by-reference

This commit is contained in:
Mahmoud Al-Qudsi
2018-09-26 20:35:30 -05:00
parent a02c54c8c7
commit a0110d296c
4 changed files with 14 additions and 13 deletions

View File

@@ -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;
}