mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 18:21:16 -03:00
Optimize the tokenize_variable_array hot spot to do less string copying
This commit is contained in:
13
common.cpp
13
common.cpp
@@ -1674,14 +1674,17 @@ int common_get_height()
|
|||||||
void tokenize_variable_array(const wcstring &val, std::vector<wcstring> &out)
|
void tokenize_variable_array(const wcstring &val, std::vector<wcstring> &out)
|
||||||
{
|
{
|
||||||
size_t pos = 0, end = val.size();
|
size_t pos = 0, end = val.size();
|
||||||
while (pos < end)
|
while (pos <= end)
|
||||||
{
|
{
|
||||||
size_t next_pos = val.find(ARRAY_SEP, pos);
|
size_t next_pos = val.find(ARRAY_SEP, pos);
|
||||||
if (next_pos == wcstring::npos) break;
|
if (next_pos == wcstring::npos)
|
||||||
out.push_back(val.substr(pos, next_pos - pos));
|
{
|
||||||
pos = next_pos + 1; //skip the separator
|
next_pos = end;
|
||||||
|
}
|
||||||
|
out.resize(out.size() + 1);
|
||||||
|
out.back().assign(val, pos, next_pos - pos);
|
||||||
|
pos = next_pos + 1; //skip the separator, or skip past the end
|
||||||
}
|
}
|
||||||
out.push_back(val.substr(pos, end - pos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool string_prefixes_string(const wchar_t *proposed_prefix, const wcstring &value)
|
bool string_prefixes_string(const wchar_t *proposed_prefix, const wcstring &value)
|
||||||
|
|||||||
Reference in New Issue
Block a user