From 9d0d9f884cebc9a1cad49679b3b64b9fdae2c964 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 13 Dec 2018 13:07:29 +0000 Subject: [PATCH] [clangd] Move the utility function to anonymous namespace, NFC. llvm-svn: 349031 --- clang-tools-extra/clangd/index/Background.cpp | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index ca3e41a29e66..6c104cbe2419 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -86,6 +86,39 @@ IncludeGraph getSubGraph(const URI &U, const IncludeGraph &FullGraph) { return IG; } + +// Creates a filter to not collect index results from files with unchanged +// digests. +// \p FileDigests contains file digests for the current indexed files, and all +// changed files will be added to \p FilesToUpdate. +decltype(SymbolCollector::Options::FileFilter) +createFileFilter(const llvm::StringMap &FileDigests, + llvm::StringMap &FilesToUpdate) { + return [&FileDigests, &FilesToUpdate](const SourceManager &SM, FileID FID) { + StringRef Path; + if (const auto *F = SM.getFileEntryForID(FID)) + Path = F->getName(); + if (Path.empty()) + return false; // Skip invalid files. + SmallString<128> AbsPath(Path); + if (std::error_code EC = + SM.getFileManager().getVirtualFileSystem()->makeAbsolute(AbsPath)) { + elog("Warning: could not make absolute file: {0}", EC.message()); + return false; // Skip files without absolute path. + } + sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); + auto Digest = digestFile(SM, FID); + if (!Digest) + return false; + auto D = FileDigests.find(AbsPath); + if (D != FileDigests.end() && D->second == Digest) + return false; // Skip files that haven't changed. + + FilesToUpdate[AbsPath] = *Digest; + return true; + }; +} + } // namespace BackgroundIndex::BackgroundIndex( @@ -281,38 +314,6 @@ void BackgroundIndex::update(StringRef MainFile, IndexFileIn Index, } } -// Creates a filter to not collect index results from files with unchanged -// digests. -// \p FileDigests contains file digests for the current indexed files, and all -// changed files will be added to \p FilesToUpdate. -decltype(SymbolCollector::Options::FileFilter) -createFileFilter(const llvm::StringMap &FileDigests, - llvm::StringMap &FilesToUpdate) { - return [&FileDigests, &FilesToUpdate](const SourceManager &SM, FileID FID) { - StringRef Path; - if (const auto *F = SM.getFileEntryForID(FID)) - Path = F->getName(); - if (Path.empty()) - return false; // Skip invalid files. - SmallString<128> AbsPath(Path); - if (std::error_code EC = - SM.getFileManager().getVirtualFileSystem()->makeAbsolute(AbsPath)) { - elog("Warning: could not make absolute file: {0}", EC.message()); - return false; // Skip files without absolute path. - } - sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); - auto Digest = digestFile(SM, FID); - if (!Digest) - return false; - auto D = FileDigests.find(AbsPath); - if (D != FileDigests.end() && D->second == Digest) - return false; // Skip files that haven't changed. - - FilesToUpdate[AbsPath] = *Digest; - return true; - }; -} - Error BackgroundIndex::index(tooling::CompileCommand Cmd, BackgroundIndexStorage *IndexStorage) { trace::Span Tracer("BackgroundIndex");