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:
const QString &name = sm->idxToFileName(sourceRow);
int score = 0;
bool res = false;
int scorep = 0, scoren = 0;
bool resn = filterByName(name, scoren);
// dont use the QStringView(QString) ctor
bool res = filterByName(QStringView(name.data(), name.size()), QStringView(pattern.data(), pattern.size()), score);
// only match file path if filename got a match
bool resp = false;
if (resn || pathLike) {
const QStringView path = sm->idxToFilePath(sourceRow);
resp = filterByPath(path, scorep);
if (res || pathLike) {
int scorep = 0;
QStringView path{sm->idxToFilePath(sourceRow)};
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);
return res;
......@@ -114,12 +111,12 @@ public Q_SLOTS:
}
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);
}
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);
}
......
......@@ -67,11 +67,12 @@ public:
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
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
......
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