[llvm] [llvm-jitlink] Avoid repeated hash lookups (NFC) (PR #130465)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 8 20:12:04 PST 2025


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

None

>From 0baf6f25e8f3b326f5dea293aeb411d26799e7b8 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 8 Mar 2025 01:05:49 -0800
Subject: [PATCH] [llvm-jitlink] Avoid repeated hash lookups (NFC)

---
 llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp
index 2fc56c9fcc72a..07dd3bd38ee61 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-macho.cpp
@@ -72,14 +72,15 @@ Error registerMachOGraphInfo(Session &S, LinkGraph &G) {
   std::lock_guard<std::mutex> Lock(S.M);
 
   auto FileName = sys::path::filename(G.getName());
-  if (S.FileInfos.count(FileName)) {
+  auto [It, Inserted] = S.FileInfos.try_emplace(FileName);
+  if (!Inserted) {
     return make_error<StringError>("When -check is passed, file names must be "
                                    "distinct (duplicate: \"" +
                                        FileName + "\")",
                                    inconvertibleErrorCode());
   }
 
-  auto &FileInfo = S.FileInfos[FileName];
+  auto &FileInfo = It->second;
   LLVM_DEBUG({
     dbgs() << "Registering MachO file info for \"" << FileName << "\"\n";
   });



More information about the llvm-commits mailing list