[lld] [lld] Avoid repeated hash lookups (NFC) (PR #112299)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 14 20:29:57 PDT 2024


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

None

>From ccea59910aae7cd0bb7c4b8347473966843ff59f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 14 Oct 2024 07:01:59 -0700
Subject: [PATCH] [lld] Avoid repeated hash lookups (NFC)

---
 lld/COFF/SymbolTable.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 3bd471389daa1f..fa09ea64babb28 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -424,13 +424,11 @@ static void reportProblemSymbols(
       if (!sym)
         continue;
       if (undefs.count(sym)) {
-        auto it = firstDiag.find(sym);
-        if (it == firstDiag.end()) {
-          firstDiag[sym] = undefDiags.size();
+        auto [it, inserted] = firstDiag.try_emplace(sym, undefDiags.size());
+        if (inserted)
           undefDiags.push_back({sym, {{file, symIndex}}});
-        } else {
+        else
           undefDiags[it->second].files.push_back({file, symIndex});
-        }
       }
       if (localImports)
         if (Symbol *imp = localImports->lookup(sym))



More information about the llvm-commits mailing list