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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 22 20:45:39 PDT 2025


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

None

>From 3bc62c58af19293eb92852d07b76b204acf18b33 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 22 Mar 2025 08:46:31 -0700
Subject: [PATCH] [DebugInfo] Avoid repeated hash lookups (NFC)

---
 llvm/lib/DebugInfo/PDB/Native/SymbolCache.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

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



More information about the llvm-commits mailing list