diff --git a/src/word_db.cc b/src/word_db.cc index c64ae01a..1e2d8a04 100644 --- a/src/word_db.cc +++ b/src/word_db.cc @@ -103,10 +103,11 @@ void WordDB::on_erase(const Buffer& buffer, BufferCoord begin, BufferCoord end) std::vector WordDB::find_prefix(const String& prefix) const { std::vector res; - for (auto& word : m_word_to_lines) + for (auto it = m_word_to_lines.lower_bound(prefix); it != m_word_to_lines.end(); ++it) { - if (prefix_match(word.first, prefix)) - res.push_back(word.first); + if (not prefix_match(it->first, prefix)) + break; + res.push_back(it->first); } return res; } diff --git a/src/word_db.hh b/src/word_db.hh index c7f8a83d..bbbfa04c 100644 --- a/src/word_db.hh +++ b/src/word_db.hh @@ -22,7 +22,7 @@ public: std::vector find_prefix(const String& prefix) const; private: - using WordToLines = std::unordered_map>; + using WordToLines = std::map>; using LineToWords = std::map>; void add_words(LineCount line, const String& content);