[PATCH] D25711: [Basic] unique_ptr-ify SourceManager::MacroArgsCacheMap (NFC)

Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 17 17:32:53 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL284442: [Basic] unique_ptr-ify SourceManager::MacroArgsCacheMap (NFC) (authored by vedantk).

Changed prior to commit:
  https://reviews.llvm.org/D25711?vs=74935&id=74937#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25711

Files:
  cfe/trunk/include/clang/Basic/SourceManager.h
  cfe/trunk/lib/Basic/SourceManager.cpp


Index: cfe/trunk/include/clang/Basic/SourceManager.h
===================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h
+++ cfe/trunk/include/clang/Basic/SourceManager.h
@@ -693,7 +693,8 @@
   /// source location.
   typedef std::map<unsigned, SourceLocation> MacroArgsMap;
 
-  mutable llvm::DenseMap<FileID, MacroArgsMap *> MacroArgsCacheMap;
+  mutable llvm::DenseMap<FileID, std::unique_ptr<MacroArgsMap>>
+      MacroArgsCacheMap;
 
   /// \brief The stack of modules being built, which is used to detect
   /// cycles in the module dependency graph as modules are being built, as
@@ -1672,7 +1673,7 @@
   std::pair<FileID, unsigned>
   getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
                                    unsigned Offset) const;
-  void computeMacroArgsCache(MacroArgsMap *&MacroArgsCache, FileID FID) const;
+  void computeMacroArgsCache(MacroArgsMap &MacroArgsCache, FileID FID) const;
   void associateFileChunkWithMacroArgExp(MacroArgsMap &MacroArgsCache,
                                          FileID FID,
                                          SourceLocation SpellLoc,
Index: cfe/trunk/lib/Basic/SourceManager.cpp
===================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp
+++ cfe/trunk/lib/Basic/SourceManager.cpp
@@ -386,8 +386,6 @@
       ContentCacheAlloc.Deallocate(I->second);
     }
   }
-
-  llvm::DeleteContainerSeconds(MacroArgsCacheMap);
 }
 
 void SourceManager::clearIDTables() {
@@ -1784,13 +1782,10 @@
 ///     0   -> SourceLocation()
 ///     100 -> Expanded macro arg location
 ///     110 -> SourceLocation()
-void SourceManager::computeMacroArgsCache(MacroArgsMap *&CachePtr,
+void SourceManager::computeMacroArgsCache(MacroArgsMap &MacroArgsCache,
                                           FileID FID) const {
   assert(FID.isValid());
-  assert(!CachePtr);
 
-  CachePtr = new MacroArgsMap();
-  MacroArgsMap &MacroArgsCache = *CachePtr;
   // Initially no macro argument chunk is present.
   MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
 
@@ -1940,9 +1935,11 @@
   if (FID.isInvalid())
     return Loc;
 
-  MacroArgsMap *&MacroArgsCache = MacroArgsCacheMap[FID];
-  if (!MacroArgsCache)
-    computeMacroArgsCache(MacroArgsCache, FID);
+  std::unique_ptr<MacroArgsMap> &MacroArgsCache = MacroArgsCacheMap[FID];
+  if (!MacroArgsCache) {
+    MacroArgsCache = llvm::make_unique<MacroArgsMap>();
+    computeMacroArgsCache(*MacroArgsCache.get(), FID);
+  }
 
   assert(!MacroArgsCache->empty());
   MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25711.74937.patch
Type: text/x-patch
Size: 2648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161018/a2405ee4/attachment.bin>


More information about the cfe-commits mailing list