[cfe-commits] r111218 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp

Douglas Gregor dgregor at apple.com
Mon Aug 16 17:40:40 PDT 2010


Author: dgregor
Date: Mon Aug 16 19:40:40 2010
New Revision: 111218

URL: http://llvm.org/viewvc/llvm-project?rev=111218&view=rev
Log:
When the # of top-level declarations changes after reparsing a
translation unit, refresh code-completion results because they've
probably changed. However, enforce a cooldown period between
refreshes, to avoid thrashing.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=111218&r1=111217&r2=111218&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Mon Aug 16 19:40:40 2010
@@ -259,6 +259,20 @@
   /// type, which is used for type equality comparisons.
   llvm::StringMap<unsigned> CachedCompletionTypes;
   
+  /// \brief The number of top-level declarations present the last time we
+  /// cached code-completion results.
+  ///
+  /// The value is used to help detect when we should repopulate the global
+  /// completion cache.
+  unsigned NumTopLevelDeclsAtLastCompletionCache;
+
+  /// \brief The number of reparses left until we'll consider updating the
+  /// code-completion cache.
+  ///
+  /// This is meant to avoid thrashing during reparsing, by not allowing the
+  /// code-completion cache to be updated on every reparse.
+  unsigned CacheCodeCompletionCoolDown;
+  
   /// \brief Cache any "global" code-completion results, so that we can avoid
   /// recomputing them with each completion.
   void CacheCodeCompletionResults();

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=111218&r1=111217&r2=111218&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Aug 16 19:40:40 2010
@@ -53,7 +53,9 @@
   : CaptureDiagnostics(false), MainFileIsAST(_MainFileIsAST), 
     CompleteTranslationUnit(true), ConcurrencyCheckValue(CheckUnlocked), 
     PreambleRebuildCounter(0), SavedMainFileBuffer(0),
-    ShouldCacheCodeCompletionResults(false) { 
+    ShouldCacheCodeCompletionResults(false),
+    NumTopLevelDeclsAtLastCompletionCache(0),
+    CacheCodeCompletionCoolDown(0) { 
 }
 
 ASTUnit::~ASTUnit() {
@@ -285,6 +287,10 @@
 
   if (CachingTimer)
     CachingTimer->stopTimer();
+  
+  // Make a note of the state when we performed this caching.
+  NumTopLevelDeclsAtLastCompletionCache = top_level_size();
+  CacheCodeCompletionCoolDown = 15;
 }
 
 void ASTUnit::ClearCachedCompletionResults() {
@@ -1411,6 +1417,14 @@
   bool Result = Parse(OverrideMainBuffer);  
   if (ReparsingTimer)
     ReparsingTimer->stopTimer();
+  
+  if (ShouldCacheCodeCompletionResults) {
+    if (CacheCodeCompletionCoolDown > 0)
+      --CacheCodeCompletionCoolDown;
+    else if (top_level_size() != NumTopLevelDeclsAtLastCompletionCache)
+      CacheCodeCompletionResults();
+  }
+  
   return Result;
 }
 





More information about the cfe-commits mailing list