From 8440b5699657cc2da3cfe36f5b974e398d534597 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 27 Sep 2024 08:31:20 -0700 Subject: [PATCH] [DWARFLinker] Avoid repeated hash lookups (NFC) --- .../llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h index b00f68c3be84e..9fb1b3f80e2ff 100644 --- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h +++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h @@ -42,15 +42,15 @@ class CachedPathResolver { // If the ParentPath has not yet been resolved, resolve and cache it for // future look-ups. - if (!ResolvedPaths.count(ParentPath)) { + auto [It, Inserted] = ResolvedPaths.try_emplace(ParentPath); + if (Inserted) { SmallString<256> RealPath; sys::fs::real_path(ParentPath, RealPath); - ResolvedPaths.insert( - {ParentPath, std::string(RealPath.c_str(), RealPath.size())}); + It->second = std::string(RealPath); } // Join the file name again with the resolved path. - SmallString<256> ResolvedPath(ResolvedPaths[ParentPath]); + SmallString<256> ResolvedPath(It->second); sys::path::append(ResolvedPath, FileName); return StringPool.internString(ResolvedPath); }