summary refs log tree commit diff
path: root/src/CompletionProxyModel.h
diff options
context:
space:
mode:
authornenomius <nenomius@protonmail.com>2022-07-23 00:52:11 +0300
committernenomius <nenomius@protonmail.com>2022-07-23 13:33:36 +0300
commit5e99bace905663bf23e00f7107d09f27b1a8acc0 (patch)
tree8a8e1d4358d312ad7625bf096a9e7d546a587123 /src/CompletionProxyModel.h
parentTranslated using Weblate (Polish) (diff)
downloadnheko-5e99bace905663bf23e00f7107d09f27b1a8acc0.tar.xz
Do less work when building completion trie
Convert to lower case only once per string.
Diffstat (limited to 'src/CompletionProxyModel.h')
-rw-r--r--src/CompletionProxyModel.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h

index 78c7ea5f..e4a1b9cd 100644 --- a/src/CompletionProxyModel.h +++ b/src/CompletionProxyModel.h
@@ -9,12 +9,19 @@ #include <QAbstractProxyModel> +enum class ElementRank +{ + first, + second +}; + template<typename Key, typename Value> struct trie { std::vector<Value> values; std::map<Key, trie> next; + template<ElementRank r> void insert(const QVector<Key> &keys, const Value &v) { auto t = this; @@ -22,7 +29,11 @@ struct trie t = &t->next[k]; } - t->values.push_back(v); + if constexpr (r == ElementRank::first) { + t->values.insert(t->values.begin(), v); + } else if constexpr (r == ElementRank::second) { + t->values.push_back(v); + } } std::vector<Value> valuesAndSubvalues(size_t limit = -1) const