diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-12-09 21:59:47 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-12-09 21:59:47 +0000 |
| commit | 319cfcda34ee202a2e9d41d599664890c8694840 (patch) | |
| tree | aedb02be49ff03c2d597729f61f03171520ef45a /src/insert_completer.cc | |
| parent | fd84ad5adf4e571d839ad2e2437af8335f60e0f3 (diff) | |
Get rid of uses of unordered_set, vector is just simpler and faster...
Diffstat (limited to 'src/insert_completer.cc')
| -rw-r--r-- | src/insert_completer.cc | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 1e57afcb..a78c6073 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -93,14 +93,11 @@ InsertCompletion complete_word(const Buffer& buffer, ByteCoord cursor_pos) String current_word{begin, end}; auto& word_db = get_word_db(buffer); - std::unordered_set<ComplAndDesc> matches; - auto bufmatches = subseq ? word_db.find_subsequence(prefix) - : word_db.find_prefix(prefix); - for (auto& match : bufmatches) - matches.insert(ComplAndDesc{match, ""}); + auto matches = subseq ? word_db.find_subsequence(prefix) + : word_db.find_prefix(prefix); if (word_db.get_word_occurences(current_word) <= 1) - matches.erase(ComplAndDesc{current_word, ""}); + unordered_erase(matches, current_word); if (other_buffers) { @@ -109,17 +106,21 @@ InsertCompletion complete_word(const Buffer& buffer, ByteCoord cursor_pos) if (buf.get() == &buffer) continue; auto& buf_word_db = get_word_db(*buf); - bufmatches = subseq ? buf_word_db.find_subsequence(prefix) - : buf_word_db.find_prefix(prefix); - for (auto& match : bufmatches) - matches.insert(ComplAndDesc{match, ""}); + auto bufmatches = subseq ? buf_word_db.find_subsequence(prefix) + : buf_word_db.find_prefix(prefix); + std::move(bufmatches.begin(), bufmatches.end(), + std::back_inserter(matches)); } } - matches.erase(ComplAndDesc{prefix, ""}); + unordered_erase(matches, prefix); + std::sort(matches.begin(), matches.end()); + matches.erase(std::unique(matches.begin(), matches.end()), matches.end()); + ComplAndDescList result; - std::copy(matches.begin(), matches.end(), - inserter(result, result.begin())); - std::sort(result.begin(), result.end()); + result.reserve(matches.size()); + for (auto& m : matches) + result.emplace_back(m, ""); + return { begin.coord(), cursor_pos, std::move(result), buffer.timestamp() }; } |
