diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-06-25 11:41:00 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-07-02 10:10:18 -0400 |
| commit | 139c33ccc4f529083b0288907caad2946a3f5a8f (patch) | |
| tree | ac4d1ed9311cdfe1e59b6e825cba228a431bf649 /src/filterwidget.cpp | |
| parent | 86e4f65eb6a2e52d0513a8c2fe1e94cd1af9967d (diff) | |
various optimizations and caching
fixed conflict list not sorting when changing parameters
switched from QDirIterator to std::filesystem, much faster
FilterWidget precompiles the list
Diffstat (limited to 'src/filterwidget.cpp')
| -rw-r--r-- | src/filterwidget.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/filterwidget.cpp b/src/filterwidget.cpp index 16a46b0e..82644658 100644 --- a/src/filterwidget.cpp +++ b/src/filterwidget.cpp @@ -30,21 +30,29 @@ void FilterWidget::clear() m_edit->clear(); } -bool FilterWidget::matches(std::function<bool (const QString& what)> pred) const +void FilterWidget::compile() { + m_compiled.clear(); + const QStringList ORList = [&] { QString filterCopy = QString(m_text); filterCopy.replace("||", ";").replace("OR", ";").replace("|", ";"); return filterCopy.split(";", QString::SkipEmptyParts); }(); - if (ORList.isEmpty() || !pred) { + // split in ORSegments that internally use AND logic + for (auto& ORSegment : ORList) { + m_compiled.push_back(ORSegment.split(" ", QString::SkipEmptyParts)); + } +} + +bool FilterWidget::matches(std::function<bool (const QString& what)> pred) const +{ + if (m_compiled.isEmpty() || !pred) { return true; } - // split in ORSegments that internally use AND logic - for (auto& ORSegment : ORList) { - QStringList ANDKeywords = ORSegment.split(" ", QString::SkipEmptyParts); + for (auto& ANDKeywords : m_compiled) { bool segmentGood = true; // check each word in the segment for match, each word needs to be matched @@ -115,6 +123,7 @@ void FilterWidget::onTextChanged() if (text != m_text) { m_text = text; + compile(); if (changed) { changed(); |
