[llvm] 8cfc99b - [DWARFLinker] Avoid repeated hash lookups (NFC) (#110377)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 28 13:10:04 PDT 2024


Author: Kazu Hirata
Date: 2024-09-28T13:10:01-07:00
New Revision: 8cfc99bd2afc4bde7317fe6c6e881c1beef1a148

URL: https://github.com/llvm/llvm-project/commit/8cfc99bd2afc4bde7317fe6c6e881c1beef1a148
DIFF: https://github.com/llvm/llvm-project/commit/8cfc99bd2afc4bde7317fe6c6e881c1beef1a148.diff

LOG: [DWARFLinker] Avoid repeated hash lookups (NFC) (#110377)

Added: 
    

Modified: 
    llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinkerDeclContext.h
index b00f68c3be84e1..9fb1b3f80e2ffa 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);
   }


        


More information about the llvm-commits mailing list