From a0cf75ec39c679776b28b178a4299cf0ad204a1c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 10 Mar 2015 13:50:25 +0000 Subject: [PATCH] Tweak WordDB implementation --- src/word_db.cc | 14 +++++++------- src/word_db.hh | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/word_db.cc b/src/word_db.cc index 4ddc69ee..2ca11dba 100644 --- a/src/word_db.cc +++ b/src/word_db.cc @@ -52,9 +52,9 @@ static WordDB::WordList get_words(const SharedString& content) return res; } -void WordDB::add_words(const WordList& words) +void WordDB::add_words(const SharedString& line) { - for (auto& w : words) + for (auto& w : get_words(line)) { WordDB::WordInfo& info = m_words[intern(w)]; ++info.refcount; @@ -63,9 +63,9 @@ void WordDB::add_words(const WordList& words) } } -void WordDB::remove_words(const WordList& words) +void WordDB::remove_words(const SharedString& line) { - for (auto& w : words) + for (auto& w : get_words(line)) { auto it = m_words.find({w, SharedString::NoCopy()}); kak_assert(it != m_words.end() and it->second.refcount > 0); @@ -81,7 +81,7 @@ WordDB::WordDB(const Buffer& buffer) for (auto line = 0_line, end = buffer.line_count(); line < end; ++line) { m_lines.push_back(buffer.line_storage(line)); - add_words(get_words(SharedString{m_lines.back()})); + add_words(SharedString{m_lines.back()}); } } @@ -112,13 +112,13 @@ void WordDB::update_db() while (old_line < modif.old_line + modif.num_removed) { kak_assert(old_line < m_lines.size()); - remove_words(get_words(SharedString{m_lines[(int)old_line++]})); + remove_words(SharedString{m_lines[(int)old_line++]}); } for (auto l = 0_line; l < modif.num_added; ++l) { new_lines.push_back(buffer.line_storage(modif.new_line + l)); - add_words(get_words(SharedString{new_lines.back()})); + add_words(SharedString{new_lines.back()}); } } while (old_line != (int)m_lines.size()) diff --git a/src/word_db.hh b/src/word_db.hh index 71cc5c3e..ad0dbadc 100644 --- a/src/word_db.hh +++ b/src/word_db.hh @@ -41,8 +41,8 @@ public: int get_word_occurences(StringView word) const; private: void update_db(); - void add_words(const WordList& words); - void remove_words(const WordList& words); + void add_words(const SharedString& line); + void remove_words(const SharedString& line); struct WordInfo {