[llvm] [AsmParser] Avoid repeated hash lookups (NFC) (PR #132328)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 20 20:51:23 PDT 2025


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

None

>From 7f0402ce8a6223197b9fe987b280560172b7a817 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 20 Mar 2025 09:36:33 -0700
Subject: [PATCH] [AsmParser] Avoid repeated hash lookups (NFC)

---
 llvm/lib/AsmParser/LLParser.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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