forked from qt-creator/qt-creator
AutoTest: Cache PCH lookups
Avoid slowing down scans of bigger projects by caching lookups of paths inside precompiled headers. Change-Id: I17652ba36ab761cc06ecce151e41253271236881 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -35,6 +35,9 @@
|
|||||||
|
|
||||||
namespace Autotest {
|
namespace Autotest {
|
||||||
|
|
||||||
|
using LookupInfo = QPair<QString, QString>;
|
||||||
|
static QHash<LookupInfo, bool> s_pchLookupCache;
|
||||||
|
|
||||||
CppParser::CppParser(ITestFramework *framework)
|
CppParser::CppParser(ITestFramework *framework)
|
||||||
: ITestParser(framework)
|
: ITestParser(framework)
|
||||||
{
|
{
|
||||||
@@ -75,6 +78,7 @@ QByteArray CppParser::getFileContent(const Utils::FilePath &filePath) const
|
|||||||
|
|
||||||
bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
|
const QString &cacheString,
|
||||||
const std::function<bool(const QString &)> &checker)
|
const std::function<bool(const QString &)> &checker)
|
||||||
{
|
{
|
||||||
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
const CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||||
@@ -83,7 +87,14 @@ bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
|||||||
return false;
|
return false;
|
||||||
const QStringList precompiledHeaders = projectParts.first()->precompiledHeaders;
|
const QStringList precompiledHeaders = projectParts.first()->precompiledHeaders;
|
||||||
auto headerContains = [&](const QString &header){
|
auto headerContains = [&](const QString &header){
|
||||||
return Utils::anyOf(snapshot.allIncludesForDocument(header), checker);
|
LookupInfo info{header, cacheString};
|
||||||
|
auto it = s_pchLookupCache.find(info);
|
||||||
|
if (it == s_pchLookupCache.end()) {
|
||||||
|
it = s_pchLookupCache.insert(info,
|
||||||
|
Utils::anyOf(snapshot.allIncludesForDocument(header),
|
||||||
|
checker));
|
||||||
|
}
|
||||||
|
return it.value();
|
||||||
};
|
};
|
||||||
return Utils::anyOf(precompiledHeaders, headerContains);
|
return Utils::anyOf(precompiledHeaders, headerContains);
|
||||||
}
|
}
|
||||||
@@ -92,7 +103,10 @@ bool CppParser::precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
|||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
const QString &headerFilePath)
|
const QString &headerFilePath)
|
||||||
{
|
{
|
||||||
return Autotest::precompiledHeaderContains(snapshot, filePath, [&](const QString &include) {
|
return Autotest::precompiledHeaderContains(snapshot,
|
||||||
|
filePath,
|
||||||
|
headerFilePath,
|
||||||
|
[&](const QString &include) {
|
||||||
return include.endsWith(headerFilePath);
|
return include.endsWith(headerFilePath);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -101,7 +115,10 @@ bool CppParser::precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
|||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
const QRegularExpression &headerFileRegex)
|
const QRegularExpression &headerFileRegex)
|
||||||
{
|
{
|
||||||
return Autotest::precompiledHeaderContains(snapshot, filePath, [&](const QString &include) {
|
return Autotest::precompiledHeaderContains(snapshot,
|
||||||
|
filePath,
|
||||||
|
headerFileRegex.pattern(),
|
||||||
|
[&](const QString &include) {
|
||||||
return headerFileRegex.match(include).hasMatch();
|
return headerFileRegex.match(include).hasMatch();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -110,6 +127,7 @@ void CppParser::release()
|
|||||||
{
|
{
|
||||||
m_cppSnapshot = CPlusPlus::Snapshot();
|
m_cppSnapshot = CPlusPlus::Snapshot();
|
||||||
m_workingCopy = CppTools::WorkingCopy();
|
m_workingCopy = CppTools::WorkingCopy();
|
||||||
|
s_pchLookupCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlusPlus::Document::Ptr CppParser::document(const Utils::FilePath &fileName)
|
CPlusPlus::Document::Ptr CppParser::document(const Utils::FilePath &fileName)
|
||||||
|
@@ -95,6 +95,7 @@ public:
|
|||||||
static bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
static bool precompiledHeaderContains(const CPlusPlus::Snapshot &snapshot,
|
||||||
const Utils::FilePath &filePath,
|
const Utils::FilePath &filePath,
|
||||||
const QRegularExpression &headerFileRegex);
|
const QRegularExpression &headerFileRegex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CPlusPlus::Snapshot m_cppSnapshot;
|
CPlusPlus::Snapshot m_cppSnapshot;
|
||||||
CppTools::WorkingCopy m_workingCopy;
|
CppTools::WorkingCopy m_workingCopy;
|
||||||
|
Reference in New Issue
Block a user