Reuse for_n_best when sorting values from complete options
While at it, remove a needless reserve() call and reserve an extra slot because "InsertCompleter::try_complete" might add one more element.
This commit is contained in:
parent
84ecd41da1
commit
d6215dc25d
|
@ -164,7 +164,7 @@ InsertCompletion complete_word(const SelectionList& sels,
|
|||
constexpr size_t max_count = 100;
|
||||
// Gather best max_count matches
|
||||
InsertCompletion::CandidateList candidates;
|
||||
candidates.reserve(std::min(matches.size(), max_count));
|
||||
candidates.reserve(std::min(matches.size(), max_count) + 1);
|
||||
|
||||
for_n_best(matches, max_count, [](auto& lhs, auto& rhs) { return rhs < lhs; },
|
||||
[&](RankedMatchAndBuffer& m) {
|
||||
|
@ -314,20 +314,19 @@ InsertCompletion complete_option(const SelectionList& sels,
|
|||
|
||||
constexpr size_t max_count = 100;
|
||||
// Gather best max_count matches
|
||||
auto greater = [](auto& lhs, auto& rhs) { return rhs < lhs; };
|
||||
auto first = matches.begin(), last = matches.end();
|
||||
std::make_heap(first, last, greater);
|
||||
InsertCompletion::CandidateList candidates;
|
||||
candidates.reserve(std::min(matches.size(), max_count));
|
||||
candidates.reserve(matches.size());
|
||||
while (candidates.size() < max_count and first != last)
|
||||
{
|
||||
if (candidates.empty() or candidates.back().completion != first->candidate()
|
||||
or candidates.back().on_select != first->on_select)
|
||||
candidates.push_back({ first->candidate().str(), first->on_select.str(),
|
||||
std::move(first->menu_entry) });
|
||||
std::pop_heap(first, last--, greater);
|
||||
}
|
||||
candidates.reserve(std::min(matches.size(), max_count) + 1);
|
||||
|
||||
for_n_best(matches, max_count, [](auto& lhs, auto& rhs) { return rhs < lhs; },
|
||||
[&](RankedMatchAndInfo& m) {
|
||||
if (not candidates.empty()
|
||||
and candidates.back().completion == m.candidate()
|
||||
and candidates.back().on_select == m.on_select)
|
||||
return false;
|
||||
candidates.push_back({ m.candidate().str(), m.on_select.str(),
|
||||
std::move(m.menu_entry) });
|
||||
return true;
|
||||
});
|
||||
|
||||
auto end = cursor_pos;
|
||||
if (match[3].matched)
|
||||
|
|
Loading…
Reference in New Issue
Block a user