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

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 22 00:09:31 PST 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/128301.diff


1 Files Affected:

- (modified) llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp (+11-15) 


``````````diff
diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
index 513b0d312345e..ad14baa0c9269 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp
@@ -24,18 +24,16 @@ using namespace llvm::logicalview;
 void LVSymbolTable::add(StringRef Name, LVScope *Function,
                         LVSectionIndex SectionIndex) {
   std::string SymbolName(Name);
-  if (SymbolNames.find(SymbolName) == SymbolNames.end()) {
-    SymbolNames.emplace(
-        std::piecewise_construct, std::forward_as_tuple(SymbolName),
-        std::forward_as_tuple(Function, 0, SectionIndex, false));
-  } else {
+  auto [It, Inserted] =
+      SymbolNames.try_emplace(SymbolName, Function, 0, SectionIndex, false);
+  if (!Inserted) {
     // Update a recorded entry with its logical scope and section index.
-    SymbolNames[SymbolName].Scope = Function;
+    It->second.Scope = Function;
     if (SectionIndex)
-      SymbolNames[SymbolName].SectionIndex = SectionIndex;
+      It->second.SectionIndex = SectionIndex;
   }
 
-  if (Function && SymbolNames[SymbolName].IsComdat)
+  if (Function && It->second.IsComdat)
     Function->setIsComdat();
 
   LLVM_DEBUG({ print(dbgs()); });
@@ -44,15 +42,13 @@ void LVSymbolTable::add(StringRef Name, LVScope *Function,
 void LVSymbolTable::add(StringRef Name, LVAddress Address,
                         LVSectionIndex SectionIndex, bool IsComdat) {
   std::string SymbolName(Name);
-  if (SymbolNames.find(SymbolName) == SymbolNames.end())
-    SymbolNames.emplace(
-        std::piecewise_construct, std::forward_as_tuple(SymbolName),
-        std::forward_as_tuple(nullptr, Address, SectionIndex, IsComdat));
-  else
+  auto [It, Inserted] = SymbolNames.try_emplace(SymbolName, nullptr, Address,
+                                                SectionIndex, IsComdat);
+  if (!Inserted)
     // Update a recorded symbol name with its logical scope.
-    SymbolNames[SymbolName].Address = Address;
+    It->second.Address = Address;
 
-  LVScope *Function = SymbolNames[SymbolName].Scope;
+  LVScope *Function = It->second.Scope;
   if (Function && IsComdat)
     Function->setIsComdat();
   LLVM_DEBUG({ print(dbgs()); });

``````````

</details>


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


More information about the llvm-commits mailing list