[llvm] [DWARFLinker] Avoid repeated hash lookups (NFC) (PR #108737)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 15 00:06:38 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/108737

None

>From c7d43a540c92e5dbf75faf280a066d05bb078403 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 13 Sep 2024 21:35:31 -0700
Subject: [PATCH] [DWARFLinker] Avoid repeated hash lookups (NFC)

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



More information about the llvm-commits mailing list