Commit 0b489b0c authored by Tomaz  Canabrava's avatar Tomaz Canabrava Committed by Kurt Hindenburg
Browse files

Use QSet to search for strings instead of QStringList

The time that it takes to search a collection of just too many strings
can take up to 48msec - tested triggering the code on /usr/lib with
around 7000 files.

changing to QSet this went down to 35msec. This is not a lot but
it's triggered at *every* mouse move event, so the gain is cummulative

The whole experience is a bit smoother.
parent ba0b3bfe
......@@ -495,10 +495,7 @@ QSharedPointer<Filter::HotSpot> FileFilter::newHotSpot(int startLine, int startC
// Return nullptr if it's not:
// <current dir>/filename
// <current dir>/childDir/filename
auto match = std::find_if(std::begin(_currentDirContents), std::end(_currentDirContents),
[filename](const QString& s) { return filename.startsWith(s); });
if (match == std::end(_currentDirContents)) {
if (!_currentDirContents.contains(filename)) {
return nullptr;
}
......@@ -509,8 +506,14 @@ void FileFilter::process()
{
const QDir dir(_session->currentWorkingDirectory());
_dirPath = dir.canonicalPath() + QLatin1Char('/');
_currentDirContents = dir.entryList(QDir::Dirs | QDir::Files);
#if QT_VERSION >= QT_VERSION_CHECK(5,14,0)
{
const auto tmpList = dir.entryList(QDir::Dirs | QDir::Files);
_currentDirContents = QSet<QString>(std::begin(tmpList), std::end(tmpList));
}
#else
_currentDirContents = QSet<QString>::fromList(dir.entryList(QDir::Dirs | QDir::Files));
#endif
RegExpFilter::process();
}
......@@ -530,7 +533,7 @@ void FileFilter::HotSpot::activate(QObject *)
FileFilter::FileFilter(Session *session) :
_session(session)
, _dirPath(QString())
, _currentDirContents(QStringList())
, _currentDirContents()
{
Profile::Ptr profile = SessionManager::instance()->sessionProfile(_session);
QString wordCharacters = profile->wordCharacters();
......
......@@ -331,7 +331,7 @@ protected:
private:
QPointer<Session> _session;
QString _dirPath;
QStringList _currentDirContents;
QSet<QString> _currentDirContents;
};
/**
......
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