From 0b489b0c69b8ae2fd9f9c61e5ea76cb7d3cbc0d0 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 31 May 2020 15:56:26 +0200 Subject: [PATCH] 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. --- src/Filter.cpp | 17 ++++++++++------- src/Filter.h | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Filter.cpp b/src/Filter.cpp index 9c38e63e..ff738d9a 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -495,10 +495,7 @@ QSharedPointer FileFilter::newHotSpot(int startLine, int startC // Return nullptr if it's not: // /filename // /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(std::begin(tmpList), std::end(tmpList)); + } +#else + _currentDirContents = QSet::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(); diff --git a/src/Filter.h b/src/Filter.h index 6d87be50..7b2bc3b8 100644 --- a/src/Filter.h +++ b/src/Filter.h @@ -331,7 +331,7 @@ protected: private: QPointer _session; QString _dirPath; - QStringList _currentDirContents; + QSet _currentDirContents; }; /**