[llvm] [MC] Avoid repeated hash lookups (NFC) (PR #123698)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 23:01:23 PST 2025


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

None

>From 4096d0ddbfbbab3a203d58f14c37dfdedb413b2a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 20 Jan 2025 10:34:36 -0800
Subject: [PATCH] [MC] Avoid repeated hash lookups (NFC)

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

diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 8ddbe929e68b94..c5a95cb3da5433 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -746,10 +746,11 @@ static void addData(SmallVectorImpl<char> &DataBytes,
 uint32_t
 WasmObjectWriter::getRelocationIndexValue(const WasmRelocationEntry &RelEntry) {
   if (RelEntry.Type == wasm::R_WASM_TYPE_INDEX_LEB) {
-    if (!TypeIndices.count(RelEntry.Symbol))
+    auto It = TypeIndices.find(RelEntry.Symbol);
+    if (It == TypeIndices.end())
       report_fatal_error("symbol not found in type index space: " +
                          RelEntry.Symbol->getName());
-    return TypeIndices[RelEntry.Symbol];
+    return It->second;
   }
 
   return RelEntry.Symbol->getIndex();



More information about the llvm-commits mailing list