forked from qt-creator/qt-creator
CppTools: Fix include filename cache logic
When resolution of a local include fails, a global resolution must be done. When doing so, re-use the cache. This will speed up the resolution for projects that mainly use the local include directives also for global headers. Change-Id: I7488c1977a44b881f90faa863d22f6276c20b147 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -237,23 +237,6 @@ bool CppSourceProcessor::checkFile(const QString &absoluteFilePath) const
|
|||||||
return fileInfo.isFile() && fileInfo.isReadable();
|
return fileInfo.isFile() && fileInfo.isReadable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve the given file name to its absolute path w.r.t. the include type.
|
|
||||||
QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType type)
|
|
||||||
{
|
|
||||||
if (type == IncludeGlobal) {
|
|
||||||
QHash<QString, QString>::ConstIterator it = m_fileNameCache.constFind(fileName);
|
|
||||||
if (it != m_fileNameCache.constEnd())
|
|
||||||
return it.value();
|
|
||||||
const QString fn = resolveFile_helper(fileName, type);
|
|
||||||
if (!fn.isEmpty())
|
|
||||||
m_fileNameCache.insert(fileName, fn);
|
|
||||||
return fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IncludeLocal, IncludeNext
|
|
||||||
return resolveFile_helper(fileName, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CppSourceProcessor::cleanPath(const QString &path)
|
QString CppSourceProcessor::cleanPath(const QString &path)
|
||||||
{
|
{
|
||||||
QString result = QDir::cleanPath(path);
|
QString result = QDir::cleanPath(path);
|
||||||
@@ -263,7 +246,8 @@ QString CppSourceProcessor::cleanPath(const QString &path)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CppSourceProcessor::resolveFile_helper(const QString &fileName, IncludeType type)
|
/// Resolve the given file name to its absolute path w.r.t. the include type.
|
||||||
|
QString CppSourceProcessor::resolveFile(const QString &fileName, IncludeType type)
|
||||||
{
|
{
|
||||||
if (isInjectedFile(fileName))
|
if (isInjectedFile(fileName))
|
||||||
return fileName;
|
return fileName;
|
||||||
@@ -271,8 +255,6 @@ QString CppSourceProcessor::resolveFile_helper(const QString &fileName, IncludeT
|
|||||||
if (QFileInfo(fileName).isAbsolute())
|
if (QFileInfo(fileName).isAbsolute())
|
||||||
return checkFile(fileName) ? fileName : QString();
|
return checkFile(fileName) ? fileName : QString();
|
||||||
|
|
||||||
auto headerPathsIt = m_headerPaths.begin();
|
|
||||||
auto headerPathsEnd = m_headerPaths.end();
|
|
||||||
if (m_currentDoc) {
|
if (m_currentDoc) {
|
||||||
if (type == IncludeLocal) {
|
if (type == IncludeLocal) {
|
||||||
const QFileInfo currentFileInfo(m_currentDoc->fileName());
|
const QFileInfo currentFileInfo(m_currentDoc->fileName());
|
||||||
@@ -285,15 +267,30 @@ QString CppSourceProcessor::resolveFile_helper(const QString &fileName, IncludeT
|
|||||||
} else if (type == IncludeNext) {
|
} else if (type == IncludeNext) {
|
||||||
const QFileInfo currentFileInfo(m_currentDoc->fileName());
|
const QFileInfo currentFileInfo(m_currentDoc->fileName());
|
||||||
const QString currentDirPath = cleanPath(currentFileInfo.dir().path());
|
const QString currentDirPath = cleanPath(currentFileInfo.dir().path());
|
||||||
|
auto headerPathsEnd = m_headerPaths.end();
|
||||||
|
auto headerPathsIt = m_headerPaths.begin();
|
||||||
for (; headerPathsIt != headerPathsEnd; ++headerPathsIt) {
|
for (; headerPathsIt != headerPathsEnd; ++headerPathsIt) {
|
||||||
if (headerPathsIt->path == currentDirPath) {
|
if (headerPathsIt->path == currentDirPath) {
|
||||||
++headerPathsIt;
|
++headerPathsIt;
|
||||||
break;
|
return resolveFile_helper(fileName, headerPathsIt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<QString, QString>::ConstIterator it = m_fileNameCache.constFind(fileName);
|
||||||
|
if (it != m_fileNameCache.constEnd())
|
||||||
|
return it.value();
|
||||||
|
const QString fn = resolveFile_helper(fileName, m_headerPaths.begin());
|
||||||
|
if (!fn.isEmpty())
|
||||||
|
m_fileNameCache.insert(fileName, fn);
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CppSourceProcessor::resolveFile_helper(const QString &fileName,
|
||||||
|
ProjectPartHeaderPaths::Iterator headerPathsIt)
|
||||||
|
{
|
||||||
|
auto headerPathsEnd = m_headerPaths.end();
|
||||||
for (; headerPathsIt != headerPathsEnd; ++headerPathsIt) {
|
for (; headerPathsIt != headerPathsEnd; ++headerPathsIt) {
|
||||||
if (headerPathsIt->isFrameworkPath())
|
if (headerPathsIt->isFrameworkPath())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ private:
|
|||||||
unsigned *revision) const;
|
unsigned *revision) const;
|
||||||
bool checkFile(const QString &absoluteFilePath) const;
|
bool checkFile(const QString &absoluteFilePath) const;
|
||||||
QString resolveFile(const QString &fileName, IncludeType type);
|
QString resolveFile(const QString &fileName, IncludeType type);
|
||||||
QString resolveFile_helper(const QString &fileName, IncludeType type);
|
QString resolveFile_helper(const QString &fileName,
|
||||||
|
ProjectPartHeaderPaths::Iterator headerPathsIt);
|
||||||
|
|
||||||
void mergeEnvironment(CPlusPlus::Document::Ptr doc);
|
void mergeEnvironment(CPlusPlus::Document::Ptr doc);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user