[llvm] [DebugInfo] Avoid repeated hash lookups (NFC) (PR #132586)

via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 22 20:46:16 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/132586.diff


1 Files Affected:

- (modified) llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp (+4-3) 


``````````diff
diff --git a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
index 95b95a5bbc509..535893b3f1a4c 100644
--- a/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp
@@ -627,14 +627,15 @@ SymbolCache::getSourceFileById(SymIndexId FileId) const {
 
 SymIndexId
 SymbolCache::getOrCreateSourceFile(const FileChecksumEntry &Checksums) const {
-  auto Iter = FileNameOffsetToId.find(Checksums.FileNameOffset);
-  if (Iter != FileNameOffsetToId.end())
+  auto [Iter, Inserted] =
+      FileNameOffsetToId.try_emplace(Checksums.FileNameOffset);
+  if (!Inserted)
     return Iter->second;
 
   SymIndexId Id = SourceFiles.size();
   auto SrcFile = std::make_unique<NativeSourceFile>(Session, Id, Checksums);
   SourceFiles.push_back(std::move(SrcFile));
-  FileNameOffsetToId[Checksums.FileNameOffset] = Id;
+  Iter->second = Id;
   return Id;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/132586


More information about the llvm-commits mailing list