From ddca79aaee9b31b4e97f6cbf4361b75ef075c8fd Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 15 Sep 2024 01:20:48 -0700 Subject: [PATCH] [DWARFLinker] Avoid repeated hash lookups (NFC) (#108737) --- llvm/lib/DWARFLinker/Parallel/OutputSections.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) 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; }