[llvm] [DWARFLinker] Avoid repeated hash lookups (NFC) (PR #110377)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 28 10:45:18 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/110377
None
>From 8440b5699657cc2da3cfe36f5b974e398d534597 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
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 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