summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-02-23 00:26:24 +0000
committerMaxime Coste <mawww@kakoune.org>2017-02-23 00:26:24 +0000
commita39f2b0c7199b7eee9e5ca6207e608a7916ba248 (patch)
tree9c8a7233045114cd4e92b94ef8eb3b24e087410c /src
parentd9abc2a156df03d264ec23c947cf7cf4c5a581ec (diff)
Refactor WordDB::add_words to be slightly faster
Diffstat (limited to 'src')
-rw-r--r--src/word_db.cc12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/word_db.cc b/src/word_db.cc
index aafc0b29..de2deefe 100644
--- a/src/word_db.cc
+++ b/src/word_db.cc
@@ -46,16 +46,14 @@ void WordDB::add_words(StringView line)
for (auto& w : get_words(line, get_extra_word_chars(*m_buffer)))
{
auto it = m_words.find(w);
- if (it == m_words.end())
+ if (it != m_words.end())
+ ++it->second.refcount;
+ else
{
auto word = intern(w);
- WordDB::WordInfo& info = m_words[word->strview()];
- info.word = word;
- info.letters = used_letters(w);
- ++info.refcount;
+ auto view = word->strview();
+ m_words.insert({view, {std::move(word), used_letters(view), 1}});
}
- else
- ++ it->second.refcount;
}
}