diff options
author | Eric Liu <ioeric@google.com> | 2019-02-18 13:12:10 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2019-02-18 13:12:10 +0000 |
commit | b355802910dab1db05b4aaaf7673e4a021891a95 (patch) | |
tree | 677e113c5561e4170d96bba3aa7bead55bea1674 /clang-tools-extra/clangd/IncludeFixer.h | |
parent | e331e63af23c91b4f3103086af7117a8f0c49f76 (diff) | |
download | bcm5719-llvm-b355802910dab1db05b4aaaf7673e4a021891a95.tar.gz bcm5719-llvm-b355802910dab1db05b4aaaf7673e4a021891a95.zip |
[clangd] Cache include fixes for diagnostics caused by the same unresolved name or incomplete type.
Summary:
Multiple diagnostics can be caused by the same unresolved name or incomplete type,
especially if the code is copy-pasted without #includes. The cache can avoid making
repetitive index requests, and thus reduce latency and allow more diagnostics to be
fixed (we limit the number of index requests for each parse).
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D58239
llvm-svn: 354268
Diffstat (limited to 'clang-tools-extra/clangd/IncludeFixer.h')
-rw-r--r-- | clang-tools-extra/clangd/IncludeFixer.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/IncludeFixer.h b/clang-tools-extra/clangd/IncludeFixer.h index da292b56b00..f1eac45d9b3 100644 --- a/clang-tools-extra/clangd/IncludeFixer.h +++ b/clang-tools-extra/clangd/IncludeFixer.h @@ -21,6 +21,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include <memory> @@ -51,7 +52,7 @@ private: std::vector<Fix> fixIncompleteType(const Type &T) const; /// Generates header insertion fixes for all symbols. Fixes are deduplicated. - std::vector<Fix> fixesForSymbols(llvm::ArrayRef<Symbol> Syms) const; + std::vector<Fix> fixesForSymbols(const SymbolSlab &Syms) const; struct UnresolvedName { std::string Name; // E.g. "X" in foo::X. @@ -79,6 +80,17 @@ private: // These collect the last unresolved name so that we can associate it with the // diagnostic. llvm::Optional<UnresolvedName> LastUnresolvedName; + + // There can be multiple diagnostics that are caused by the same unresolved + // name or incomplete type in one parse, especially when code is + // copy-and-pasted without #includes. We cache the index results based on + // index requests. + mutable llvm::StringMap<SymbolSlab> FuzzyFindCache; + mutable llvm::DenseMap<SymbolID, SymbolSlab> LookupCache; + // Returns None if the number of index requests has reached the limit. + llvm::Optional<const SymbolSlab *> + fuzzyFindCached(const FuzzyFindRequest &Req) const; + llvm::Optional<const SymbolSlab *> lookupCached(const SymbolID &ID) const; }; } // namespace clangd |