mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Optimize sort_and_prioritize_completions
Don't continuously shift items in the vector by using std::remove_if instead, followed by a single call to ->erase().
This commit is contained in:
parent
b575e120cf
commit
d9be55e504
1 changed files with 3 additions and 6 deletions
|
@ -262,12 +262,9 @@ void completions_sort_and_prioritize(std::vector<completion_t> *comps) {
|
|||
}
|
||||
|
||||
// Throw out completions whose match types are less suitable than the best.
|
||||
size_t i = comps->size();
|
||||
while (i--) {
|
||||
if (comps->at(i).match.type > best_type) {
|
||||
comps->erase(comps->begin() + i);
|
||||
}
|
||||
}
|
||||
comps->erase(std::remove_if(comps->begin(), comps->end(), [&] (const completion_t &comp) {
|
||||
return comp.match.type > best_type;
|
||||
}), comps->end());
|
||||
|
||||
// Sort, provided COMPLETION_DONT_SORT isn't set
|
||||
stable_sort(comps->begin(), comps->end(), completion_t::is_naturally_less_than);
|
||||
|
|
Loading…
Reference in a new issue