[llvm] [ExecutionEngine] Avoid repeated hash lookups (NFC) (PR #109563)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 22:42:23 PDT 2024


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

None

>From 65795243b7a9f2b1a38a1265396f504af8e0c9cb Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 21 Sep 2024 09:39:06 -0700
Subject: [PATCH] [ExecutionEngine] Avoid repeated hash lookups (NFC)

---
 .../JITLink/DefineExternalSectionStartAndEndSymbols.h        | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/JITLink/DefineExternalSectionStartAndEndSymbols.h b/llvm/lib/ExecutionEngine/JITLink/DefineExternalSectionStartAndEndSymbols.h
index 4a492ee2f7d07b..49cfc5dec25bb5 100644
--- a/llvm/lib/ExecutionEngine/JITLink/DefineExternalSectionStartAndEndSymbols.h
+++ b/llvm/lib/ExecutionEngine/JITLink/DefineExternalSectionStartAndEndSymbols.h
@@ -71,10 +71,7 @@ class DefineExternalSectionStartAndEndSymbols {
 
 private:
   SectionRange &getSectionRange(Section &Sec) {
-    auto I = SectionRanges.find(&Sec);
-    if (I == SectionRanges.end())
-      I = SectionRanges.insert(std::make_pair(&Sec, SectionRange(Sec))).first;
-    return I->second;
+    return SectionRanges.try_emplace(&Sec, Sec).first->second;
   }
 
   DenseMap<Section *, SectionRange> SectionRanges;



More information about the llvm-commits mailing list