From 9269a5e0a8e0ea816de832ce231570889d1003ab Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 1 Sep 2018 13:18:34 -0700 Subject: [PATCH] Clean up abbreviation implementation a bit --- src/expand.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/expand.cpp b/src/expand.cpp index 46b9ea07a..5bcd896e7 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -1146,18 +1146,19 @@ bool fish_xdm_login_hack_hack_hack_hack(std::vector *cmds, int argc return result; } -std::unordered_map abbreviations; +static owning_lock> s_abbreviations; void update_abbr_cache(const wchar_t *op, const wcstring &varname) { wcstring abbr; if (!unescape_string(varname.substr(wcslen(L"_fish_abbr_")), &abbr, 0, STRING_STYLE_VAR)) { debug(1, L"Abbreviation var '%ls' is not correctly encoded, ignoring it.", varname.c_str()); return; } - abbreviations.erase(abbr); + auto abbreviations = s_abbreviations.acquire(); + abbreviations->erase(abbr); if (wcscmp(op, L"ERASE") != 0) { const auto expansion = env_get(varname); if (!expansion.missing_or_empty()) { - abbreviations.emplace(std::make_pair(abbr, expansion->as_string())); + abbreviations->emplace(abbr, expansion->as_string()); } } } @@ -1165,20 +1166,9 @@ void update_abbr_cache(const wchar_t *op, const wcstring &varname) { bool expand_abbreviation(const wcstring &src, wcstring *output) { if (src.empty()) return false; - auto abbr = abbreviations.find(src); - if (abbr == abbreviations.end()) return false; + auto abbreviations = s_abbreviations.acquire(); + auto abbr = abbreviations->find(src); + if (abbr == abbreviations->end()) return false; if (output != NULL) output->assign(abbr->second); return true; - -#if 0 - for (auto abbr : abbreviations) { - if (src == abbr.first) { - // We found a matching abbreviation. Set output to the expansion. - if (output != NULL) output->assign(abbr.second); - return true; - } - } - - return false; -#endif }