diff --git a/llvm/lib/DWARFLinker/Parallel/OutputSections.h b/llvm/lib/DWARFLinker/Parallel/OutputSections.h index d2e4622aa764..da47f53b6c3d 100644 --- a/llvm/lib/DWARFLinker/Parallel/OutputSections.h +++ b/llvm/lib/DWARFLinker/Parallel/OutputSections.h @@ -371,16 +371,11 @@ public: /// If descriptor does not exist then creates it. SectionDescriptor & getOrCreateSectionDescriptor(DebugSectionKind SectionKind) { - SectionsSetTy::iterator It = SectionDescriptors.find(SectionKind); + auto [It, Inserted] = SectionDescriptors.try_emplace(SectionKind); - if (It == SectionDescriptors.end()) { - SectionDescriptor *Section = - new SectionDescriptor(SectionKind, GlobalData, Format, Endianness); - auto Result = SectionDescriptors.try_emplace(SectionKind, Section); - assert(Result.second); - - It = Result.first; - } + if (Inserted) + It->second = std::make_shared(SectionKind, GlobalData, + Format, Endianness); return *It->second; }