Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 23, 2025

@llvm/pr-subscribers-platform-windows

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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;
 }
 

@llvmbot
Copy link
Member

llvmbot commented Mar 23, 2025

@llvm/pr-subscribers-debuginfo

Author: Kazu Hirata (kazutakahirata)

Changes

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 --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;
 }
 

@kazutakahirata kazutakahirata merged commit 0a08d71 into llvm:main Mar 23, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_DebugInfo branch March 23, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants