summaryrefslogtreecommitdiff
path: root/src/insert_completer.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-02-20 19:19:26 +0000
committerMaxime Coste <mawww@kakoune.org>2017-02-20 19:28:02 +0000
commitfe2d0fab718078231c31f18607666a3deabb931c (patch)
tree08e25e6a74100527bd9828b6c138c6023d3481ca /src/insert_completer.cc
parent5eef2b910521a5df917574d1cde7f63502311dca (diff)
Fix performance of word completion with many different selections
Fixes #1228
Diffstat (limited to 'src/insert_completer.cc')
-rw-r--r--src/insert_completer.cc24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index f61a9c1d..f11c0bf7 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -90,25 +90,24 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
return {};
BufferCoord word_begin;
- String prefix;
- IdMap<int> sel_word_counts;
+ StringView prefix;
+ UnorderedMap<StringView, int> sel_word_counts;
for (int i = 0; i < sels.size(); ++i)
{
Utf8It end{buffer.iterator_at(sels[i].cursor()), buffer};
Utf8It begin = end-1;
- if (not skip_while_reverse(begin, buffer.begin(),
- [&](Codepoint c) { return is_word_pred(c); }))
+ if (not skip_while_reverse(begin, buffer.begin(), is_word_pred))
++begin;
if (i == sels.main_index())
{
word_begin = begin.base().coord();
- prefix = buffer.string(word_begin, end.base().coord());
+ prefix = buffer.substr(word_begin, end.base().coord());
}
- skip_while(end, buffer.end(), [&](Codepoint c) { return is_word_pred(c); });
+ skip_while(end, buffer.end(), is_word_pred);
- auto word = buffer.string(begin.base().coord(), end.base().coord());
+ StringView word = buffer.substr(begin.base().coord(), end.base().coord());
++sel_word_counts[word];
}
@@ -137,8 +136,8 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
// Remove words that are being edited
for (auto& word_count : sel_word_counts)
{
- if (get_word_db(buffer).get_word_occurences(word_count.key) <= word_count.value)
- unordered_erase(matches, StringView{word_count.key});
+ if (get_word_db(buffer).get_word_occurences(word_count.first) <= word_count.second)
+ unordered_erase(matches, word_count.first);
}
if (other_buffers)
@@ -156,7 +155,7 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
if (RankedMatch match{word, prefix})
matches.emplace_back(match, nullptr);
- unordered_erase(matches, StringView{prefix});
+ unordered_erase(matches, prefix);
std::sort(matches.begin(), matches.end());
matches.erase(std::unique(matches.begin(), matches.end()), matches.end());
@@ -206,7 +205,7 @@ InsertCompletion complete_filename(const SelectionList& sels,
if (begin == pos)
return {};
- auto prefix = buffer.string(begin.coord(), pos.coord());
+ StringView prefix = buffer.substr(begin.coord(), pos.coord());
if (require_slash and not contains(prefix, '/'))
return {};
@@ -273,8 +272,7 @@ InsertCompletion complete_option(const SelectionList& sels,
if (cursor_pos.line == coord.line and cursor_pos.column >= coord.column)
{
- StringView query = buffer[coord.line].substr(
- coord.column, cursor_pos.column - coord.column);
+ StringView query = buffer.substr(coord, cursor_pos);
const ColumnCount tabstop = options["tabstop"].get<int>();
const ColumnCount column = get_column(buffer, tabstop, cursor_pos);