From ecd386c67b3e3c00546df4624b53a5c36e7623ff Mon Sep 17 00:00:00 2001 From: Ville Nummela Date: Thu, 25 Apr 2019 11:06:58 +0300 Subject: [PATCH] QmakePM: Only schedule update when files are added/removed When a file is saved, the directory is also touched. If files are not added or removed, it is not necessary to reparse the project. Change-Id: I718db68362d41ba936629be880f739ad79b8cb6f Fixes: QTCREATORBUG-22361 Reviewed-by: Christian Kandeler --- .../qmakeprojectmanager/qmakeparsernodes.cpp | 33 +++++++++++++------ .../qmakeprojectmanager/qmakeparsernodes.h | 1 + 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp index 671cd5bfecf..7b050a5ed64 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.cpp @@ -1623,25 +1623,38 @@ void QmakeProFile::applyEvaluate(QmakeEvalResult *evalResult) m_wildcardWatcher = std::make_unique(); QObject::connect( m_wildcardWatcher.get(), &Utils::FileSystemWatcher::directoryChanged, - [this]() { - scheduleUpdate(); + [this](QString path) { + QStringList directoryContents = QDir(path).entryList(); + if (m_wildcardDirectoryContents.value(path) != directoryContents) { + m_wildcardDirectoryContents.insert(path, directoryContents); + scheduleUpdate(); + } }); } - m_wildcardWatcher->addDirectories( - Utils::filtered(result->directoriesWithWildcards.toList(), - [this](const QString &path) { - return !m_wildcardWatcher->watchesDirectory(path); - }), Utils::FileSystemWatcher::WatchModifiedDate); + const QStringList directoriesToAdd = Utils::filtered( + result->directoriesWithWildcards.toList(), + [this](const QString &path) { + return !m_wildcardWatcher->watchesDirectory(path); + }); + for (QString path : directoriesToAdd) + m_wildcardDirectoryContents.insert(path, QDir(path).entryList()); + m_wildcardWatcher->addDirectories(directoriesToAdd, + Utils::FileSystemWatcher::WatchModifiedDate); } if (m_wildcardWatcher) { if (result->directoriesWithWildcards.isEmpty()) { m_wildcardWatcher.reset(); + m_wildcardDirectoryContents.clear(); } else { - m_wildcardWatcher->removeDirectories( - Utils::filtered(m_wildcardWatcher->directories(), + const QStringList directoriesToRemove = + Utils::filtered( + m_wildcardWatcher->directories(), [&result](const QString &path) { return !result->directoriesWithWildcards.contains(path); - })); + }); + m_wildcardWatcher->removeDirectories(directoriesToRemove); + for (QString path : directoriesToRemove) + m_wildcardDirectoryContents.remove(path); } } diff --git a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h index 6f0e13a5c95..68b406fe63a 100644 --- a/src/plugins/qmakeprojectmanager/qmakeparsernodes.h +++ b/src/plugins/qmakeprojectmanager/qmakeparsernodes.h @@ -370,6 +370,7 @@ private: InstallsList m_installsList; std::unique_ptr m_wildcardWatcher; + QMap m_wildcardDirectoryContents; // Async stuff QFutureWatcher m_parseFutureWatcher;