summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-01-15 13:58:55 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-01-15 19:26:38 +0000
commit8eef019cf8c98bf6e7580f3aa321443dd5d7138f (patch)
treebad469d17d2e1a365285936c668698a82243f4ed /src
parent76d806e98d5e80f7f0c233d561371b89b8724c23 (diff)
Do not store lines to word in word db, just keep the old lines alive
Diffstat (limited to 'src')
-rw-r--r--src/word_db.cc25
-rw-r--r--src/word_db.hh6
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<SharedString, MemoryDomain::WordDB>;
+ using WordList = Vector<StringView>;
template<typename MatchFunc>
WordList find_matching(StringView str, MatchFunc match)
{
@@ -50,12 +50,12 @@ private:
int refcount;
};
using WordToInfo = UnorderedMap<SharedString, WordInfo, MemoryDomain::WordDB>;
- using LineToWords = Vector<WordList, MemoryDomain::WordDB>;
+ using Lines = Vector<SharedString, MemoryDomain::WordDB>;
safe_ptr<const Buffer> m_buffer;
size_t m_timestamp;
WordToInfo m_words;
- LineToWords m_line_to_words;
+ Lines m_lines;
};
}