[llvm] [dsymutil] Avoid repeated hash lookups (NFC) (#126190) (PR #126346)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 7 20:55:56 PST 2025


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

None

>From cdccc4349d254a1818eb642c59e425a465b38317 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 7 Feb 2025 08:00:21 -0800
Subject: [PATCH] [dsymutil] Avoid repeated hash lookups (NFC) (#126190)

---
 llvm/tools/dsymutil/BinaryHolder.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/tools/dsymutil/BinaryHolder.cpp b/llvm/tools/dsymutil/BinaryHolder.cpp
index 5daaa6755b2957f..7588a33eb46b22a 100644
--- a/llvm/tools/dsymutil/BinaryHolder.cpp
+++ b/llvm/tools/dsymutil/BinaryHolder.cpp
@@ -176,8 +176,8 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
 
   // Try the cache first.
   std::lock_guard<std::mutex> Lock(MemberCacheMutex);
-  if (MemberCache.count(Key))
-    return *MemberCache[Key];
+  if (auto It = MemberCache.find(Key); It != MemberCache.end())
+    return *It->second;
 
   // Create a new ObjectEntry, but don't add it to the cache yet. Loading of
   // the archive members might fail and we don't want to lock the whole archive
@@ -228,8 +228,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
   if (OE->Objects.empty())
     return errorCodeToError(errc::no_such_file_or_directory);
 
-  MemberCache[Key] = std::move(OE);
-  return *MemberCache[Key];
+  return *(MemberCache[Key] = std::move(OE));
 }
 
 Expected<const BinaryHolder::ObjectEntry &>



More information about the llvm-commits mailing list