ExecutableInfo: Share getClangIncludeDirAndVersion's cache

Share the common cache with ClangToolRunControl and
DocumentClangToolRunner.

Change-Id: I47c6a1844459e80e9ea0336b5aa72db0265d3a30
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Jarek Kobus
2023-01-09 17:35:07 +01:00
parent 8d6c168631
commit f73e787bd1
2 changed files with 13 additions and 13 deletions

View File

@@ -218,30 +218,21 @@ void DocumentClangToolRunner::run()
runNext(); runNext();
} }
QPair<FilePath, QString> getClangIncludeDirAndVersion(ClangToolRunner *runner)
{
static QMap<FilePath, QPair<FilePath, QString>> cache;
const FilePath tool = runner->executable();
auto it = cache.find(tool);
if (it == cache.end())
it = cache.insert(tool, getClangIncludeDirAndVersion(tool));
return it.value();
}
void DocumentClangToolRunner::runNext() void DocumentClangToolRunner::runNext()
{ {
if (m_currentRunner) if (m_currentRunner)
m_currentRunner.release()->deleteLater(); m_currentRunner.release()->deleteLater();
m_currentRunner.reset(m_runnerCreators.isEmpty() ? nullptr : m_runnerCreators.takeFirst()()); m_currentRunner.reset(m_runnerCreators.isEmpty() ? nullptr : m_runnerCreators.takeFirst()());
if (m_currentRunner) { if (m_currentRunner) {
auto [clangIncludeDir, clangVersion] = getClangIncludeDirAndVersion(m_currentRunner.get()); const auto [clangIncludeDir, clangVersion] = getClangIncludeDirAndVersion(
m_currentRunner->executable());
qCDebug(LOG) << Q_FUNC_INFO << m_currentRunner->executable() << clangIncludeDir qCDebug(LOG) << Q_FUNC_INFO << m_currentRunner->executable() << clangIncludeDir
<< clangVersion << m_fileInfo.file; << clangVersion << m_fileInfo.file;
if (m_currentRunner->executable().isEmpty() || clangIncludeDir.isEmpty() || clangVersion.isEmpty() if (m_currentRunner->executable().isEmpty() || clangIncludeDir.isEmpty() || clangVersion.isEmpty()
|| (m_document->isModified() && !m_currentRunner->supportsVFSOverlay())) { || (m_document->isModified() && !m_currentRunner->supportsVFSOverlay())) {
runNext(); runNext();
} else { } else {
AnalyzeUnit unit(m_fileInfo, clangIncludeDir, clangVersion); const AnalyzeUnit unit(m_fileInfo, clangIncludeDir, clangVersion);
QTC_ASSERT(FilePath::fromString(unit.file).exists(), runNext(); return;); QTC_ASSERT(FilePath::fromString(unit.file).exists(), runNext(); return;);
m_currentRunner->setVFSOverlay(vfso().overlayFilePath().toString()); m_currentRunner->setVFSOverlay(vfso().overlayFilePath().toString());
if (!m_currentRunner->run(unit.file, unit.arguments)) if (!m_currentRunner->run(unit.file, unit.arguments))

View File

@@ -214,7 +214,7 @@ QString queryVersion(const FilePath &clangToolPath, QueryFailMode failMode)
return {}; return {};
} }
QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolPath) static QPair<FilePath, QString> clangIncludeDirAndVersion(const FilePath &clangToolPath)
{ {
const FilePath dynamicResourceDir = queryResourceDir(clangToolPath); const FilePath dynamicResourceDir = queryResourceDir(clangToolPath);
const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy); const QString dynamicVersion = queryVersion(clangToolPath, QueryFailMode::Noisy);
@@ -223,6 +223,15 @@ QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolP
return {dynamicResourceDir / "include", dynamicVersion}; return {dynamicResourceDir / "include", dynamicVersion};
} }
QPair<FilePath, QString> getClangIncludeDirAndVersion(const FilePath &clangToolPath)
{
static QMap<FilePath, QPair<FilePath, QString>> cache;
auto it = cache.find(clangToolPath);
if (it == cache.end())
it = cache.insert(clangToolPath, clangIncludeDirAndVersion(clangToolPath));
return it.value();
}
QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> ClazyStandaloneInfo::cache; QHash<Utils::FilePath, QPair<QDateTime, ClazyStandaloneInfo>> ClazyStandaloneInfo::cache;
} // namespace Internal } // namespace Internal