Skip to content

Commit

Permalink
ASTUnit::FileDecls: Use unique_ptr to simplify memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
dwblaikie committed Apr 29, 2020
1 parent 2dd4596 commit d9485df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Frontend/ASTUnit.h
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Frontend/ASTUnit.cpp
Expand Up @@ -224,7 +224,7 @@ struct ASTUnit::ASTWriterData {
};

void ASTUnit::clearFileLevelDecls() {
llvm::DeleteContainerSeconds(FileDecls);
FileDecls.clear();
}

/// After failing to build a precompiled preamble (due to
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d9485df

Please sign in to comment.