Commit 8fb90fae authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Minor optimizations for quickopen

parent dda6dc54
Pipeline #73667 passed with stage
in 6 minutes and 37 seconds
...@@ -76,21 +76,18 @@ protected: ...@@ -76,21 +76,18 @@ protected:
const QString &name = sm->idxToFileName(sourceRow); const QString &name = sm->idxToFileName(sourceRow);
int score = 0; int score = 0;
bool res = false; // dont use the QStringView(QString) ctor
int scorep = 0, scoren = 0; bool res = filterByName(QStringView(name.data(), name.size()), QStringView(pattern.data(), pattern.size()), score);
bool resn = filterByName(name, scoren);
// only match file path if filename got a match // only match file path if filename got a match
bool resp = false; if (res || pathLike) {
if (resn || pathLike) { int scorep = 0;
const QStringView path = sm->idxToFilePath(sourceRow); QStringView path{sm->idxToFilePath(sourceRow)};
resp = filterByPath(path, scorep); bool resp = filterByPath(path, QStringView(pattern.data(), pattern.size()), scorep);
score += scorep;
res = res || resp;
} }
// store the score for sorting later
score = scoren + scorep;
res = resp || resn;
sm->setScoreForIndex(sourceRow, score); sm->setScoreForIndex(sourceRow, score);
return res; return res;
...@@ -114,12 +111,12 @@ public Q_SLOTS: ...@@ -114,12 +111,12 @@ public Q_SLOTS:
} }
private: private:
inline bool filterByPath(const QStringView path, int &score) const static inline bool filterByPath(QStringView path, QStringView pattern, int &score)
{ {
return kfts::fuzzy_match(pattern, path, score); return kfts::fuzzy_match(pattern, path, score);
} }
inline bool filterByName(const QString &name, int &score) const static inline bool filterByName(QStringView name, QStringView pattern, int &score)
{ {
return kfts::fuzzy_match(pattern, name, score); return kfts::fuzzy_match(pattern, name, score);
} }
......
...@@ -67,11 +67,12 @@ public: ...@@ -67,11 +67,12 @@ public:
return m_modelEntries.at(row).fileName; return m_modelEntries.at(row).fileName;
} }
const QStringView idxToFilePath(int row) const QStringView idxToFilePath(int row) const
{ {
const auto &path = m_modelEntries.at(row).filePath; const QString &path = m_modelEntries.at(row).filePath;
QStringView pth(path.data(), path.size());
// handle exceptional non-saved file case // handle exceptional non-saved file case
return path.startsWith(m_projectBase) ? QStringView(path).mid(m_projectBase.size()) : path; return pth.startsWith(QStringView(m_projectBase.data(), m_projectBase.size())) ? pth.mid(m_projectBase.size()) : pth;
} }
int idxScore(const QModelIndex &idx) const int idxScore(const QModelIndex &idx) const
......
Supports Markdown
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