[llvm] 619688f - [IR] Avoid repeated hash lookups (NFC) (#110450)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 06:47:43 PDT 2024


Author: Kazu Hirata
Date: 2024-09-30T06:47:39-07:00
New Revision: 619688f3d37b9a74ee50ba8a336ab0680f32d2fa

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

LOG: [IR] Avoid repeated hash lookups (NFC) (#110450)

Added: 
    

Modified: 
    llvm/lib/IR/AsmWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 70e3af941bf77b..280e347739cdb6 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1338,12 +1338,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) {
 void SlotTracker::CreateAttributeSetSlot(AttributeSet AS) {
   assert(AS.hasAttributes() && "Doesn't need a slot!");
 
-  as_iterator I = asMap.find(AS);
-  if (I != asMap.end())
-    return;
-
-  unsigned DestSlot = asNext++;
-  asMap[AS] = DestSlot;
+  if (asMap.try_emplace(AS, asNext).second)
+    ++asNext;
 }
 
 /// Create a new slot for the specified Module


        


More information about the llvm-commits mailing list