[clang] d9485df - ASTUnit::FileDecls: Use unique_ptr to simplify memory management
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 17:59:55 PDT 2020
Author: David Blaikie
Date: 2020-04-28T17:59:45-07:00
New Revision: d9485dfbc12b277e4ba222f4c0e371c5914fe51e
URL: https://github.com/llvm/llvm-project/commit/d9485dfbc12b277e4ba222f4c0e371c5914fe51e
DIFF: https://github.com/llvm/llvm-project/commit/d9485dfbc12b277e4ba222f4c0e371c5914fe51e.diff
LOG: ASTUnit::FileDecls: Use unique_ptr to simplify memory management
Added:
Modified:
clang/include/clang/Frontend/ASTUnit.h
clang/lib/Frontend/ASTUnit.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h
index a36655150d4e..50ab86ebad97 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -172,7 +172,7 @@ class ASTUnit {
/// 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.
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 7920aa2b5cbe..57d025b7c32e 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -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);
More information about the cfe-commits
mailing list