[llvm] cb729be - [CodeGen] Avoid repeated hash lookups (NFC) (#132513)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 22 08:08:31 PDT 2025


Author: Kazu Hirata
Date: 2025-03-22T08:08:28-07:00
New Revision: cb729be11cbfb4f0f180e683e2c2d2a3750d4374

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

LOG: [CodeGen] Avoid repeated hash lookups (NFC) (#132513)

Added: 
    

Modified: 
    llvm/lib/CodeGen/GCMetadata.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GCMetadata.cpp b/llvm/lib/CodeGen/GCMetadata.cpp
index f33008c9e0f23..fa87b14e708e1 100644
--- a/llvm/lib/CodeGen/GCMetadata.cpp
+++ b/llvm/lib/CodeGen/GCMetadata.cpp
@@ -41,8 +41,10 @@ CollectorMetadataAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
   for (auto &F : M) {
     if (F.isDeclaration() || !F.hasGC())
       continue;
-    if (auto GCName = F.getGC(); !Map.contains(GCName))
-      Map[GCName] = getGCStrategy(GCName);
+    auto GCName = F.getGC();
+    auto [It, Inserted] = Map.try_emplace(GCName);
+    if (Inserted)
+      It->second = getGCStrategy(GCName);
   }
   return R;
 }


        


More information about the llvm-commits mailing list