forked from qt-creator/qt-creator
ProjectExplorer: prepare for parallelization of recursive file scan
Change-Id: Ia2db3ef0fe619907c1ed30b8f984de4de04cc477 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -83,12 +83,17 @@ CMakeBuildSystem::CMakeBuildSystem(CMakeBuildConfiguration *bc)
|
||||
|
||||
// Cache mime check result for speed up
|
||||
if (!isIgnored) {
|
||||
auto it = m_mimeBinaryCache.find(mimeType.name());
|
||||
if (it != m_mimeBinaryCache.end()) {
|
||||
if (auto it = m_mimeBinaryCache.get<std::optional<bool>>(
|
||||
[mimeType](const QHash<QString, bool> &cache) -> std::optional<bool> {
|
||||
auto it = cache.find(mimeType.name());
|
||||
if (it != cache.end())
|
||||
return *it;
|
||||
return {};
|
||||
})) {
|
||||
isIgnored = *it;
|
||||
} else {
|
||||
isIgnored = TreeScanner::isMimeBinary(mimeType, fn);
|
||||
m_mimeBinaryCache[mimeType.name()] = isIgnored;
|
||||
m_mimeBinaryCache.writeLocked()->insert(mimeType.name(), isIgnored);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <projectexplorer/buildsystem.h>
|
||||
|
||||
#include <utils/synchronizedvalue.h>
|
||||
#include <utils/temporarydirectory.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
@@ -221,7 +222,7 @@ private:
|
||||
|
||||
ProjectExplorer::TreeScanner m_treeScanner;
|
||||
std::shared_ptr<ProjectExplorer::FolderNode> m_allFiles;
|
||||
QHash<QString, bool> m_mimeBinaryCache;
|
||||
Utils::SynchronizedValue<QHash<QString, bool>> m_mimeBinaryCache;
|
||||
|
||||
bool m_waitingForParse = false;
|
||||
bool m_combinedScanAndParseResult = false;
|
||||
|
@@ -332,7 +332,11 @@ CompilationDatabaseBuildSystem::CompilationDatabaseBuildSystem(Target *target)
|
||||
this, &CompilationDatabaseBuildSystem::updateDeploymentData);
|
||||
}
|
||||
|
||||
CompilationDatabaseBuildSystem::~CompilationDatabaseBuildSystem() = default;
|
||||
CompilationDatabaseBuildSystem::~CompilationDatabaseBuildSystem()
|
||||
{
|
||||
if (m_parser)
|
||||
delete m_parser;
|
||||
}
|
||||
|
||||
void CompilationDatabaseBuildSystem::triggerParsing()
|
||||
{
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cppeditor/cppprojectfile.h>
|
||||
#include <utils/synchronizedvalue.h>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
@@ -29,7 +30,7 @@ public:
|
||||
QStringList extras;
|
||||
};
|
||||
|
||||
using MimeBinaryCache = QHash<QString, bool>;
|
||||
using MimeBinaryCache = Utils::SynchronizedValue<QHash<QString, bool>>;
|
||||
|
||||
QStringList filterFromFileName(const QStringList &flags, const QString &fileName);
|
||||
|
||||
|
@@ -130,6 +130,15 @@ CompilationDbParser::CompilationDbParser(const QString &projectName,
|
||||
});
|
||||
}
|
||||
|
||||
CompilationDbParser::~CompilationDbParser()
|
||||
{
|
||||
if (m_treeScanner && !m_treeScanner->isFinished()) {
|
||||
auto future = m_treeScanner->future();
|
||||
future.cancel();
|
||||
future.waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
void CompilationDbParser::start()
|
||||
{
|
||||
// Check hash first.
|
||||
@@ -158,12 +167,17 @@ void CompilationDbParser::start()
|
||||
|
||||
// Cache mime check result for speed up
|
||||
if (!isIgnored) {
|
||||
auto it = m_mimeBinaryCache.find(mimeType.name());
|
||||
if (it != m_mimeBinaryCache.end()) {
|
||||
if (auto it = m_mimeBinaryCache.get<std::optional<bool>>(
|
||||
[mimeType](const QHash<QString, bool> &cache) -> std::optional<bool> {
|
||||
auto it = cache.find(mimeType.name());
|
||||
if (it != cache.end())
|
||||
return *it;
|
||||
return {};
|
||||
})) {
|
||||
isIgnored = *it;
|
||||
} else {
|
||||
isIgnored = TreeScanner::isMimeBinary(mimeType, fn);
|
||||
m_mimeBinaryCache[mimeType.name()] = isIgnored;
|
||||
m_mimeBinaryCache.writeLocked()->insert(mimeType.name(), isIgnored);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,7 @@ public:
|
||||
MimeBinaryCache &mimeBinaryCache,
|
||||
ProjectExplorer::BuildSystem::ParseGuard &&guard,
|
||||
QObject *parent = nullptr);
|
||||
~CompilationDbParser();
|
||||
|
||||
|
||||
void setPreviousProjectFileHash(const QByteArray &fileHash) { m_projectFileHash = fileHash; }
|
||||
|
@@ -25,14 +25,6 @@ const char EXCLUDED_FILES_KEY[] = "ExcludedFiles";
|
||||
NimProjectScanner::NimProjectScanner(Project *project)
|
||||
: m_project(project)
|
||||
{
|
||||
m_scanner.setFilter([this](const Utils::MimeType &, const FilePath &fp) {
|
||||
const QString path = fp.toString();
|
||||
return excludedFiles().contains(path)
|
||||
|| path.endsWith(".nimproject")
|
||||
|| path.contains(".nimproject.user")
|
||||
|| path.contains(".nimble.user");
|
||||
});
|
||||
|
||||
connect(&m_directoryWatcher, &FileSystemWatcher::directoryChanged,
|
||||
this, &NimProjectScanner::directoryChanged);
|
||||
connect(&m_directoryWatcher, &FileSystemWatcher::fileChanged,
|
||||
@@ -91,6 +83,13 @@ void NimProjectScanner::saveSettings()
|
||||
|
||||
void NimProjectScanner::startScan()
|
||||
{
|
||||
m_scanner.setFilter(
|
||||
[excludedFiles = excludedFiles()](const Utils::MimeType &, const FilePath &fp) {
|
||||
const QString path = fp.toString();
|
||||
return excludedFiles.contains(path) || path.endsWith(".nimproject")
|
||||
|| path.contains(".nimproject.user") || path.contains(".nimble.user");
|
||||
});
|
||||
|
||||
m_scanner.asyncScanForFiles(m_project->projectDirectory());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user