From 8eef019cf8c98bf6e7580f3aa321443dd5d7138f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 15 Jan 2015 13:58:55 +0000 Subject: [PATCH] Do not store lines to word in word db, just keep the old lines alive --- src/word_db.cc | 25 ++++++++++++------------- src/word_db.hh | 6 +++--- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/word_db.cc b/src/word_db.cc index 2043cbcd..53a478c1 100644 --- a/src/word_db.cc +++ b/src/word_db.cc @@ -77,11 +77,11 @@ void WordDB::remove_words(const WordList& words) WordDB::WordDB(const Buffer& buffer) : m_buffer{&buffer}, m_timestamp{buffer.timestamp()} { - m_line_to_words.reserve((int)buffer.line_count()); + m_lines.reserve((int)buffer.line_count()); for (auto line = 0_line, end = buffer.line_count(); line < end; ++line) { - m_line_to_words.push_back(get_words(buffer[line])); - add_words(m_line_to_words.back()); + m_lines.push_back(buffer[line]); + add_words(get_words(m_lines.back())); } } @@ -95,8 +95,7 @@ void WordDB::update_db() if (modifs.empty()) return; - - LineToWords new_lines; + Lines new_lines; new_lines.reserve((int)buffer.line_count()); auto old_line = 0_line; @@ -105,14 +104,14 @@ void WordDB::update_db() kak_assert(0_line <= modif.new_line and modif.new_line < buffer.line_count()); kak_assert(old_line <= modif.old_line); while (old_line < modif.old_line) - new_lines.push_back(std::move(m_line_to_words[(int)old_line++])); + new_lines.push_back(std::move(m_lines[(int)old_line++])); kak_assert((int)new_lines.size() == (int)modif.new_line); while (old_line <= modif.old_line + modif.num_removed) { - kak_assert(old_line < m_line_to_words.size()); - remove_words(m_line_to_words[(int)old_line++]); + kak_assert(old_line < m_lines.size()); + remove_words(get_words(m_lines[(int)old_line++])); } for (auto l = 0_line; l <= modif.num_added; ++l) @@ -120,14 +119,14 @@ void WordDB::update_db() if (modif.new_line + l >= buffer.line_count()) break; - new_lines.push_back(get_words(buffer[modif.new_line + l])); - add_words(new_lines.back()); + new_lines.push_back(buffer[modif.new_line + l]); + add_words(get_words(new_lines.back())); } } - while (old_line != (int)m_line_to_words.size()) - new_lines.push_back(std::move(m_line_to_words[(int)old_line++])); + while (old_line != (int)m_lines.size()) + new_lines.push_back(std::move(m_lines[(int)old_line++])); - m_line_to_words = std::move(new_lines); + m_lines = std::move(new_lines); } int WordDB::get_word_occurences(StringView word) const diff --git a/src/word_db.hh b/src/word_db.hh index fbb32371..8034560f 100644 --- a/src/word_db.hh +++ b/src/word_db.hh @@ -22,7 +22,7 @@ public: WordDB(const WordDB&) = delete; WordDB(WordDB&&) = default; - using WordList = Vector; + using WordList = Vector; template WordList find_matching(StringView str, MatchFunc match) { @@ -50,12 +50,12 @@ private: int refcount; }; using WordToInfo = UnorderedMap; - using LineToWords = Vector; + using Lines = Vector; safe_ptr m_buffer; size_t m_timestamp; WordToInfo m_words; - LineToWords m_line_to_words; + Lines m_lines; }; }