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

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 21:07:35 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/128127.diff


1 Files Affected:

- (modified) llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp (+8-14) 


``````````diff
diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
index 82d14861e1e10..67aa71027687a 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
@@ -155,29 +155,23 @@ class LVForwardReferences {
   }
 
   void add(StringRef Name, TypeIndex TIForward) {
-    if (ForwardTypesNames.find(Name) == ForwardTypesNames.end()) {
-      ForwardTypesNames.emplace(
-          std::piecewise_construct, std::forward_as_tuple(Name),
-          std::forward_as_tuple(TIForward, TypeIndex::None()));
-    } else {
+    auto [It, Inserted] =
+        ForwardTypesNames.try_emplace(Name, TIForward, TypeIndex::None());
+    if (!Inserted) {
       // Update a recorded definition with its reference.
-      ForwardTypesNames[Name].first = TIForward;
-      add(TIForward, ForwardTypesNames[Name].second);
+      It->second.first = TIForward;
+      add(TIForward, It->second.second);
     }
   }
 
   // Update a previously recorded forward reference with its definition.
   void update(StringRef Name, TypeIndex TIReference) {
-    auto It = ForwardTypesNames.find(Name);
-    if (It != ForwardTypesNames.end()) {
+    auto [It, Inserted] =
+        ForwardTypesNames.try_emplace(Name, TypeIndex::None(), TIReference);
+    if (!Inserted) {
       // Update the recorded forward reference with its definition.
       It->second.second = TIReference;
       add(It->second.first, TIReference);
-    } else {
-      // We have not seen the forward reference. Insert the definition.
-      ForwardTypesNames.emplace(
-          std::piecewise_construct, std::forward_as_tuple(Name),
-          std::forward_as_tuple(TypeIndex::None(), TIReference));
     }
   }
 

``````````

</details>


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


More information about the llvm-commits mailing list