From d2e15e5f1efa1ef160a2d4f40ab61180477d1f14 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 21 Sep 2017 11:43:59 +0200 Subject: Clang: Add file cache The database is using file path integer ids to handle file paths because otherwise we would save many redundant data. This patch is improving it further with the introduction of a database based file path cache. The entries are now divided in a directory path and file name. This is quite handy for directory based file watching. Change-Id: I03f2e388e43f3d521d6bf8e39dfb95eb2309dc73 Reviewed-by: Tim Jenssen --- .../source/sourcerangeextractor.cpp | 29 +++++----------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp') diff --git a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp index 399a7353f3..d275cfe4e2 100644 --- a/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp +++ b/src/tools/clangrefactoringbackend/source/sourcerangeextractor.cpp @@ -28,14 +28,7 @@ #include "sourcelocationsutils.h" #include - -#if defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wunused-parameter" -#elif defined(_MSC_VER) -# pragma warning(push) -# pragma warning( disable : 4100 ) -#endif +#include #include #include @@ -43,18 +36,12 @@ #include #include -#if defined(__GNUC__) -# pragma GCC diagnostic pop -#elif defined(_MSC_VER) -# pragma warning(pop) -#endif - namespace ClangBackEnd { SourceRangeExtractor::SourceRangeExtractor( const clang::SourceManager &sourceManager, const clang::LangOptions &languageOptions, - ClangBackEnd::FilePathCache &filePathCache, + FilePathCachingInterface &filePathCache, SourceRangesContainer &sourceRangesContainer) : sourceManager(sourceManager), languageOptions(languageOptions), @@ -127,16 +114,14 @@ const clang::SourceRange SourceRangeExtractor::extendSourceRangeToLastTokenEnd(c return {sourceRange.getBegin(), endLocation}; } -void SourceRangeExtractor::insertSourceRange(uint fileId, - Utils::PathString &&filePath, +void SourceRangeExtractor::insertSourceRange(FilePathId filePathId, const clang::FullSourceLoc &startLocation, uint startOffset, const clang::FullSourceLoc &endLocation, uint endOffset, Utils::SmallString &&lineSnippet) { - sourceRangesContainer.insertFilePath(fileId, std::move(filePath)); - sourceRangesContainer.insertSourceRange(fileId, + sourceRangesContainer.insertSourceRange(filePathId, startLocation.getSpellingLineNumber(), startLocation.getSpellingColumnNumber(), startOffset, @@ -146,7 +131,7 @@ void SourceRangeExtractor::insertSourceRange(uint fileId, std::move(lineSnippet)); } -FilePathIndex SourceRangeExtractor::findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const +FilePathId SourceRangeExtractor::findFileId(clang::FileID fileId, const clang::FileEntry *fileEntry) const { auto found = m_fileIdMapping.find(fileId.getHashValue()); if (found != m_fileIdMapping.end()) { @@ -154,7 +139,7 @@ FilePathIndex SourceRangeExtractor::findFileId(clang::FileID fileId, const clang } auto filePath = absolutePath(fileEntry->getName()); - return filePathCache.stringId(fromNativePath(filePath)); + return filePathCache.filePathId(fromNativePath(filePath)); } void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange) @@ -176,13 +161,11 @@ void SourceRangeExtractor::addSourceRange(const clang::SourceRange &sourceRange) endOffset); insertSourceRange(findFileId(fileId, fileEntry), - fromNativePath(absolutePath(fileEntry->getName())), startSourceLocation, startOffset, endSourceLocation, endOffset, std::move(lineSnippet)); - } } -- cgit v1.2.1