diff options
-rw-r--r-- | include/clang/Basic/SourceManager.h | 5 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 15 |
2 files changed, 9 insertions, 11 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 45187e58cb..7f1b31f69b 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -693,7 +693,8 @@ class SourceManager : public RefCountedBase<SourceManager> { /// 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 @@ private: 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, diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 5dcb8811e2..4727b56b58 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -386,8 +386,6 @@ SourceManager::~SourceManager() { ContentCacheAlloc.Deallocate(I->second); } } - - llvm::DeleteContainerSeconds(MacroArgsCacheMap); } void SourceManager::clearIDTables() { @@ -1784,13 +1782,10 @@ SourceLocation SourceManager::translateLineCol(FileID FID, /// 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 @@ SourceManager::getMacroArgExpandedLocation(SourceLocation Loc) const { 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); |