diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 8dc4889e3ae88f..bc5a782f20cc61 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -216,7 +216,8 @@ class ASTWriter : public ASTDeserializationListener, /// indicates the index that this particular vector has in the global one. unsigned FirstDeclIndex; }; - using FileDeclIDsTy = llvm::DenseMap; + using FileDeclIDsTy = + llvm::DenseMap>; /// Map from file SLocEntries to info about the file-level declarations /// that it contains. diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 31d004f6c946c4..03121515a5cc88 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2898,8 +2898,10 @@ void ASTWriter::WriteTypeDeclOffsets() { void ASTWriter::WriteFileDeclIDsMap() { using namespace llvm; - SmallVector, 64> SortedFileDeclIDs( - FileDeclIDs.begin(), FileDeclIDs.end()); + SmallVector, 64> SortedFileDeclIDs; + SortedFileDeclIDs.reserve(FileDeclIDs.size()); + for (const auto &P : FileDeclIDs) + SortedFileDeclIDs.push_back(std::make_pair(P.first, P.second.get())); llvm::sort(SortedFileDeclIDs, llvm::less_first()); // Join the vectors of DeclIDs from all files. @@ -4297,9 +4299,7 @@ ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, } } -ASTWriter::~ASTWriter() { - llvm::DeleteContainerSeconds(FileDeclIDs); -} +ASTWriter::~ASTWriter() = default; const LangOptions &ASTWriter::getLangOpts() const { assert(WritingAST && "can't determine lang opts when not writing AST"); @@ -5366,9 +5366,9 @@ void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { return; assert(SM.getSLocEntry(FID).isFile()); - DeclIDInFileInfo *&Info = FileDeclIDs[FID]; + std::unique_ptr &Info = FileDeclIDs[FID]; if (!Info) - Info = new DeclIDInFileInfo(); + Info = std::make_unique(); std::pair LocDecl(Offset, ID); LocDeclIDsTy &Decls = Info->DeclIDs;