From a8b11cb2c5c60d7e766b4b4bbea47609b71837f1 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 22 Mar 2018 15:35:32 +0100 Subject: 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 --- .../source/symbolsvisitorbase.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h index dd4b61ec45..dc3d0ff232 100644 --- a/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h +++ b/src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h @@ -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 m_filePathIndices; + std::vector m_filePathIndices; FilePathCachingInterface &m_filePathCache; const clang::SourceManager *m_sourceManager = nullptr; }; -- cgit v1.2.1