From cdccc4349d254a1818eb642c59e425a465b38317 Mon Sep 17 00:00:00 2001 From: Kazu Hirata 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 5daaa6755b295..7588a33eb46b2 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 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