[llvm] 968ecc7 - [AsmParser] Avoid repeated hash lookups (NFC) (#132328)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 21 08:00:33 PDT 2025


Author: Kazu Hirata
Date: 2025-03-21T08:00:30-07:00
New Revision: 968ecc7bfe2eb98bd087fbb0ac529a4c1b81b482

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

LOG: [AsmParser] Avoid repeated hash lookups (NFC) (#132328)

Added: 
    

Modified: 
    llvm/lib/AsmParser/LLParser.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index c8d792981793d..d1ec575111d34 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -942,7 +942,8 @@ bool LLParser::parseMDNodeID(MDNode *&Result) {
     return true;
 
   // If not a forward reference, just return it now.
-  if (auto It = NumberedMetadata.find(MID); It != NumberedMetadata.end()) {
+  auto [It, Inserted] = NumberedMetadata.try_emplace(MID);
+  if (!Inserted) {
     Result = It->second;
     return false;
   }
@@ -952,7 +953,7 @@ bool LLParser::parseMDNodeID(MDNode *&Result) {
   FwdRef = std::make_pair(MDTuple::getTemporary(Context, {}), IDLoc);
 
   Result = FwdRef.first.get();
-  NumberedMetadata[MID].reset(Result);
+  It->second.reset(Result);
   return false;
 }
 


        


More information about the llvm-commits mailing list