yvvan updated this revision to Diff 101533.
yvvan added a comment.

Remove global completion cache part because it's probably not always valid.


https://reviews.llvm.org/D33493

Files:
  include/clang/Frontend/ASTUnit.h
  lib/Frontend/ASTUnit.cpp


Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1148,6 +1148,8 @@
   if (SavedMainFileBuffer)
     TranslateStoredDiagnostics(getFileManager(), getSourceManager(),
                                PreambleDiagnostics, StoredDiagnostics);
+  else
+    SrcLocCache.clear();
 
   if (!Act->Execute())
     goto error;
@@ -2579,20 +2581,25 @@
 
   SmallVector<StoredDiagnostic, 4> Result;
   Result.reserve(Diags.size());
-  const FileEntry *PreviousFE = nullptr;
-  FileID FID;
+
   for (const StandaloneDiagnostic &SD : Diags) {
     // Rebuild the StoredDiagnostic.
     if (SD.Filename.empty())
       continue;
     const FileEntry *FE = FileMgr.getFile(SD.Filename);
     if (!FE)
       continue;
-    if (FE != PreviousFE) {
+    FileID FID;
+    SourceLocation FileLoc;
+    auto ItFileID = SrcLocCache.find(SD.Filename);
+    if (ItFileID == SrcLocCache.end()) {
       FID = SrcMgr.translateFile(FE);
-      PreviousFE = FE;
+      FileLoc = SrcMgr.getLocForStartOfFile(FID);
+      SrcLocCache.insert(std::make_pair(SD.Filename, FileLoc));
+    } else {
+      FileLoc = ItFileID->second;
     }
-    SourceLocation FileLoc = SrcMgr.getLocForStartOfFile(FID);
+
     if (FileLoc.isInvalid())
       continue;
     SourceLocation L = FileLoc.getLocWithOffset(SD.LocOffset);
Index: include/clang/Frontend/ASTUnit.h
===================================================================
--- include/clang/Frontend/ASTUnit.h
+++ include/clang/Frontend/ASTUnit.h
@@ -185,6 +185,12 @@
   /// some number of calls.
   unsigned PreambleRebuildCounter;
 
+  /// \brief Cache pairs "filename - source location"
+  ///
+  /// This cache is used when loading preambule to increase performance
+  /// of that loading
+  std::map<const std::string, SourceLocation> SrcLocCache;
+
 public:
   class PreambleData {
     const FileEntry *File;


Index: lib/Frontend/ASTUnit.cpp
===================================================================
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1148,6 +1148,8 @@
   if (SavedMainFileBuffer)
     TranslateStoredDiagnostics(getFileManager(), getSourceManager(),
                                PreambleDiagnostics, StoredDiagnostics);
+  else
+    SrcLocCache.clear();
 
   if (!Act->Execute())
     goto error;
@@ -2579,20 +2581,25 @@
 
   SmallVector<StoredDiagnostic, 4> Result;
   Result.reserve(Diags.size());
-  const FileEntry *PreviousFE = nullptr;
-  FileID FID;
+
   for (const StandaloneDiagnostic &SD : Diags) {
     // Rebuild the StoredDiagnostic.
     if (SD.Filename.empty())
       continue;
     const FileEntry *FE = FileMgr.getFile(SD.Filename);
     if (!FE)
       continue;
-    if (FE != PreviousFE) {
+    FileID FID;
+    SourceLocation FileLoc;
+    auto ItFileID = SrcLocCache.find(SD.Filename);
+    if (ItFileID == SrcLocCache.end()) {
       FID = SrcMgr.translateFile(FE);
-      PreviousFE = FE;
+      FileLoc = SrcMgr.getLocForStartOfFile(FID);
+      SrcLocCache.insert(std::make_pair(SD.Filename, FileLoc));
+    } else {
+      FileLoc = ItFileID->second;
     }
-    SourceLocation FileLoc = SrcMgr.getLocForStartOfFile(FID);
+
     if (FileLoc.isInvalid())
       continue;
     SourceLocation L = FileLoc.getLocWithOffset(SD.LocOffset);
Index: include/clang/Frontend/ASTUnit.h
===================================================================
--- include/clang/Frontend/ASTUnit.h
+++ include/clang/Frontend/ASTUnit.h
@@ -185,6 +185,12 @@
   /// some number of calls.
   unsigned PreambleRebuildCounter;
 
+  /// \brief Cache pairs "filename - source location"
+  ///
+  /// This cache is used when loading preambule to increase performance
+  /// of that loading
+  std::map<const std::string, SourceLocation> SrcLocCache;
+
 public:
   class PreambleData {
     const FileEntry *File;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to