diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-04-10 17:23:48 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-04-10 17:23:48 +0000 |
commit | 28a83f57003469fb615ad27dd34bcf5b0a10da8c (patch) | |
tree | 9e59e61651170d8f2e02b6b6f630f274a600f3c3 /tools | |
parent | 42963612a4187b55685b7f75489c11abd3fa100e (diff) |
[code-complete] Introduce CodeCompletionTUInfo which will be used for caching
code-completion related strings specific to a translation unit (ASTContext and related data)
CodeCompletionAllocator does such limited caching, by caching the name assigned
to a DeclContext*, but that is not the appropriate place since that object has
a lifetime that can extend beyond that of an ASTContext.
Introduce CodeCompletionTUInfo which will be always tied to a translation unit
to do this kind of caching and move the caching of CodeCompletionAllocator into this
object, and propagate it to all the places where it will be needed.
The plan is to extend the caching where appropriate, using CodeCompletionTUInfo,
to avoid re-calculating code-completion strings.
Part of rdar://10796159.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154408 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libclang/CIndexCodeCompletion.cpp | 20 | ||||
-rw-r--r-- | tools/libclang/CXCursor.cpp | 10 |
2 files changed, 17 insertions, 13 deletions
diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index 95ed3c4843..303fb1f9d5 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -264,7 +264,8 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults { CachedCompletionAllocator; /// \brief Allocator used to store code completion results. - clang::CodeCompletionAllocator CodeCompletionAllocator; + IntrusiveRefCntPtr<clang::GlobalCodeCompletionAllocator> + CodeCompletionAllocator; /// \brief Context under which completion occurred. enum clang::CodeCompletionContext::Kind ContextKind; @@ -300,6 +301,7 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults( FileSystemOpts(FileSystemOpts), FileMgr(new FileManager(FileSystemOpts)), SourceMgr(new SourceManager(*Diag, *FileMgr)), + CodeCompletionAllocator(new clang::GlobalCodeCompletionAllocator), Contexts(CXCompletionContext_Unknown), ContainerKind(CXCursor_InvalidCode), ContainerUSR(createCXString("")), @@ -503,13 +505,15 @@ static unsigned long long getContextsForContextKind( namespace { class CaptureCompletionResults : public CodeCompleteConsumer { AllocatedCXCodeCompleteResults &AllocatedResults; + CodeCompletionTUInfo CCTUInfo; SmallVector<CXCompletionResult, 16> StoredResults; CXTranslationUnit *TU; public: CaptureCompletionResults(AllocatedCXCodeCompleteResults &Results, CXTranslationUnit *TranslationUnit) : CodeCompleteConsumer(true, false, true, false), - AllocatedResults(Results), TU(TranslationUnit) { } + AllocatedResults(Results), CCTUInfo(Results.CodeCompletionAllocator), + TU(TranslationUnit) { } ~CaptureCompletionResults() { Finish(); } virtual void ProcessCodeCompleteResults(Sema &S, @@ -519,8 +523,8 @@ namespace { StoredResults.reserve(StoredResults.size() + NumResults); for (unsigned I = 0; I != NumResults; ++I) { CodeCompletionString *StoredCompletion - = Results[I].CreateCodeCompletionString(S, - AllocatedResults.CodeCompletionAllocator); + = Results[I].CreateCodeCompletionString(S, getAllocator(), + getCodeCompletionTUInfo()); CXCompletionResult R; R.CursorKind = Results[I].CursorKind; @@ -607,8 +611,8 @@ namespace { StoredResults.reserve(StoredResults.size() + NumCandidates); for (unsigned I = 0; I != NumCandidates; ++I) { CodeCompletionString *StoredCompletion - = Candidates[I].CreateSignatureString(CurrentArg, S, - AllocatedResults.CodeCompletionAllocator); + = Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(), + getCodeCompletionTUInfo()); CXCompletionResult R; R.CursorKind = CXCursor_NotImplemented; @@ -618,8 +622,10 @@ namespace { } virtual CodeCompletionAllocator &getAllocator() { - return AllocatedResults.CodeCompletionAllocator; + return *AllocatedResults.CodeCompletionAllocator; } + + virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() { return CCTUInfo; } private: void Finish() { diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index 84a6ccb07e..0533c84a57 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -1076,13 +1076,12 @@ CXCompletionString clang_getCursorCompletionString(CXCursor cursor) { Decl *decl = getCursorDecl(cursor); if (NamedDecl *namedDecl = dyn_cast_or_null<NamedDecl>(decl)) { ASTUnit *unit = getCursorASTUnit(cursor); - CodeCompletionAllocator *Allocator - = unit->getCursorCompletionAllocator().getPtr(); CodeCompletionResult Result(namedDecl); CodeCompletionString *String = Result.CreateCodeCompletionString(unit->getASTContext(), unit->getPreprocessor(), - *Allocator); + unit->getCodeCompletionTUInfo().getAllocator(), + unit->getCodeCompletionTUInfo()); return String; } } @@ -1090,13 +1089,12 @@ CXCompletionString clang_getCursorCompletionString(CXCursor cursor) { MacroDefinition *definition = getCursorMacroDefinition(cursor); const IdentifierInfo *MacroInfo = definition->getName(); ASTUnit *unit = getCursorASTUnit(cursor); - CodeCompletionAllocator *Allocator - = unit->getCursorCompletionAllocator().getPtr(); CodeCompletionResult Result(const_cast<IdentifierInfo *>(MacroInfo)); CodeCompletionString *String = Result.CreateCodeCompletionString(unit->getASTContext(), unit->getPreprocessor(), - *Allocator); + unit->getCodeCompletionTUInfo().getAllocator(), + unit->getCodeCompletionTUInfo()); return String; } return NULL; |