diff options
author | Marco Bubke <marco.bubke@qt.io> | 2018-03-22 15:35:32 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2018-03-27 14:45:41 +0000 |
commit | a8b11cb2c5c60d7e766b4b4bbea47609b71837f1 (patch) | |
tree | 7f03fa239eea3da6f2b56d619846b4aa0d675b43 | |
parent | 576eb3370c9b14c4423ba3a8e7e72a977342bf86 (diff) | |
download | qt-creator-a8b11cb2c5c60d7e766b4b4bbea47609b71837f1.tar.gz |
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>
-rw-r--r-- | src/tools/clangrefactoringbackend/source/symbolsvisitorbase.h | 19 |
1 files 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<uint, FilePathId> m_filePathIndices; + std::vector<FilePathId> m_filePathIndices; FilePathCachingInterface &m_filePathCache; const clang::SourceManager *m_sourceManager = nullptr; }; |