Commit 9af46e24 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Optimize project file filtering a bit

Typing into the filter line edit is too slow for the first couple of
chars. So when we have only one char, do simple string searching that
is much faster. For the rest, use simple fuzzy matching as we don't
use score here and all the extra work is not needed.
parent 6201a6ca
Pipeline #122043 passed with stage
in 3 minutes and 11 seconds
......@@ -44,9 +44,8 @@ protected:
return true;
}
int score = 0; // unused intentionally
QString file = index.data().toString();
return kfts::fuzzy_match(m_pattern, file, score);
const QString file = index.data().toString();
return kfts::fuzzy_match_simple(m_pattern, file);
}
private:
......
......@@ -74,6 +74,10 @@ static bool fuzzy_match_recursive(QStringView::const_iterator pattern,
// Public interface
static bool fuzzy_match_simple(const QStringView pattern, const QStringView str)
{
if (pattern.length() == 1) {
return str.contains(pattern, Qt::CaseInsensitive);
}
auto patternIt = pattern.cbegin();
for (auto strIt = str.cbegin(); strIt != str.cend() && patternIt != pattern.cend(); ++strIt) {
if (strIt->toLower() == patternIt->toLower()) {
......@@ -85,6 +89,18 @@ static bool fuzzy_match_simple(const QStringView pattern, const QStringView str)
static bool fuzzy_match(const QStringView pattern, const QStringView str, int &outScore)
{
if (pattern.length() == 1) {
const int found = str.indexOf(pattern, Qt::CaseInsensitive);
if (found >= 0) {
outScore = 250 - found;
outScore += pattern.at(0) == str.at(found);
return true;
} else {
outScore = 0;
return false;
}
}
// simple substring matching to flush out non-matching stuff
auto patternIt = pattern.cbegin();
bool lower = patternIt->isLower();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment