ASTUnit::FileDecls: Use unique_ptr to simplify memory management
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 29 Apr 2020 00:58:53 +0000 (17:58 -0700)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 29 Apr 2020 00:59:45 +0000 (17:59 -0700)
clang/include/clang/Frontend/ASTUnit.h
clang/lib/Frontend/ASTUnit.cpp

index a366551..50ab86e 100644 (file)
@@ -172,7 +172,7 @@ private:
 
   /// Sorted (by file offset) vector of pairs of file offset/Decl.
   using LocDeclsTy = SmallVector<std::pair<unsigned, Decl *>, 64>;
-  using FileDeclsTy = llvm::DenseMap<FileID, LocDeclsTy *>;
+  using FileDeclsTy = llvm::DenseMap<FileID, std::unique_ptr<LocDeclsTy>>;
 
   /// Map from FileID to the file-level declarations that it contains.
   /// The files and decls are only local (and non-preamble) ones.
index 7920aa2..57d025b 100644 (file)
@@ -224,7 +224,7 @@ struct ASTUnit::ASTWriterData {
 };
 
 void ASTUnit::clearFileLevelDecls() {
-  llvm::DeleteContainerSeconds(FileDecls);
+  FileDecls.clear();
 }
 
 /// After failing to build a precompiled preamble (due to
@@ -2436,9 +2436,9 @@ void ASTUnit::addFileLevelDecl(Decl *D) {
   if (FID.isInvalid())
     return;
 
-  LocDeclsTy *&Decls = FileDecls[FID];
+  std::unique_ptr<LocDeclsTy> &Decls = FileDecls[FID];
   if (!Decls)
-    Decls = new LocDeclsTy();
+    Decls = std::make_unique<LocDeclsTy>();
 
   std::pair<unsigned, Decl *> LocDecl(Offset, D);