Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Feb 22, 2025

@llvm/pr-subscribers-debuginfo

Author: Kazu Hirata (kazutakahirata)

Changes

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

@kazutakahirata kazutakahirata merged commit 94b8106 into llvm:main Feb 22, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_DebugInfo branch February 22, 2025 10:13
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