Clang: Improve access to caching structure

The clang file id is counted from zero, so it better to use a vector
instead of a hash with all the overhead.

Change-Id: Iaf201898e9e16005d196b5b49065f15f9d3d2dfa
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-03-22 15:35:32 +01:00
parent 576eb3370c
commit a8b11cb2c5

View File

@@ -59,19 +59,22 @@ public:
FilePathId filePathId(const clang::FileEntry *fileEntry)
{
if (fileEntry) {
uint fileHash = fileEntry->getUID();
uint fileId = fileEntry->getUID();
auto found = m_filePathIndices.find(fileHash);
if (fileId >= m_filePathIndices.size())
m_filePathIndices.resize(fileId + 1);
if (found != m_filePathIndices.end())
return found->second;
FilePathId &filePathId = m_filePathIndices[fileId];
if (filePathId.isValid())
return filePathId;
auto filePath = fileEntry->getName();
FilePathId filePathId = m_filePathCache.filePathId(FilePath::fromNativeFilePath(absolutePath(filePath)));
FilePathId newFilePathId = m_filePathCache.filePathId(FilePath::fromNativeFilePath(absolutePath(filePath)));
m_filePathIndices.emplace(fileHash, filePathId);
filePathId = newFilePathId;
return filePathId;
return newFilePathId;
}
return {};
@@ -126,7 +129,7 @@ public:
}
protected:
std::unordered_map<uint, FilePathId> m_filePathIndices;
std::vector<FilePathId> m_filePathIndices;
FilePathCachingInterface &m_filePathCache;
const clang::SourceManager *m_sourceManager = nullptr;
};