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

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 15 01:20:51 PDT 2024


Author: Kazu Hirata
Date: 2024-09-15T01:20:48-07:00
New Revision: ddca79aaee9b31b4e97f6cbf4361b75ef075c8fd

URL: https://github.com/llvm/llvm-project/commit/ddca79aaee9b31b4e97f6cbf4361b75ef075c8fd
DIFF: https://github.com/llvm/llvm-project/commit/ddca79aaee9b31b4e97f6cbf4361b75ef075c8fd.diff

LOG: [DWARFLinker] Avoid repeated hash lookups (NFC) (#108737)

Added: 
    

Modified: 
    llvm/lib/DWARFLinker/Parallel/OutputSections.h

Removed: 
    


################################################################################
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