Optimize completion model by only splitting on normal spaces

This commit is contained in:
Nicolas Werner 2021-05-30 00:25:45 +02:00
parent 18ff58edb3
commit dfe2495d9a
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -19,7 +19,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
, max_completions_(max_completions) , max_completions_(max_completions)
{ {
setSourceModel(model); setSourceModel(model);
QRegularExpression splitPoints("\\s+|-"); QChar splitPoints(' ');
// insert all the full texts // insert all the full texts
for (int i = 0; i < sourceModel()->rowCount(); i++) { for (int i = 0; i < sourceModel()->rowCount(); i++) {
@ -48,7 +48,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
.toString() .toString()
.toLower(); .toLower();
for (const auto &e : string1.split(splitPoints)) { for (const auto &e : string1.splitRef(splitPoints)) {
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14 if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
trie_.insert(e.toUcs4(), i); trie_.insert(e.toUcs4(), i);
} }
@ -59,7 +59,7 @@ CompletionProxyModel::CompletionProxyModel(QAbstractItemModel *model,
.toLower(); .toLower();
if (!string2.isEmpty()) { if (!string2.isEmpty()) {
for (const auto &e : string2.split(splitPoints)) { for (const auto &e : string2.splitRef(splitPoints)) {
if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14 if (!e.isEmpty()) // NOTE(Nico): Use Qt::SkipEmptyParts in Qt 5.14
trie_.insert(e.toUcs4(), i); trie_.insert(e.toUcs4(), i);
} }