expand: Use wcstring for the abbr prefix

This mainly is conceptually a bit simpler. The comment about making it
cheaper is entirely misplaced since this is quite far away from being
important.

Even expanding 1000 abbrs, it doesn't show up in the profile.
This commit is contained in:
Fabian Homborg 2019-05-22 22:31:45 +02:00
parent 212246ecaa
commit 9a541d9ed4

View File

@ -1217,13 +1217,12 @@ maybe_t<wcstring> expand_abbreviation(const wcstring &src, const environment_t &
}
std::map<wcstring, wcstring> get_abbreviations(const environment_t &vars) {
// TODO: try to make this cheaper
const size_t fish_abbr_len = std::wcslen(L"_fish_abbr_");
const wcstring prefix = L"_fish_abbr_";
auto names = vars.get_names(0);
std::map<wcstring, wcstring> result;
for (const wcstring &name : names) {
if (string_prefixes_string(L"_fish_abbr_", name)) {
result[name.substr(fish_abbr_len)] = vars.get(name)->as_string();
if (string_prefixes_string(prefix, name)) {
result[name.substr(prefix.size())] = vars.get(name)->as_string();
}
}
return result;