[llvm] [DebugInfo] Avoid repeated map lookups (NFC) (PR #128826)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 22:20:41 PST 2025


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

None

>From a3264940106db05c8acb74cc3931240b8eb8f42e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 25 Feb 2025 09:08:47 -0800
Subject: [PATCH] [DebugInfo] Avoid repeated map lookups (NFC)

---
 .../DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
index 67aa71027687a..97214948d014a 100644
--- a/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
@@ -268,10 +268,9 @@ class LVStringRecords {
 
   void add(TypeIndex TI, StringRef String) {
     static uint32_t Index = 0;
-    if (Strings.find(TI) == Strings.end())
-      Strings.emplace(
-          std::piecewise_construct, std::forward_as_tuple(TI),
-          std::forward_as_tuple(++Index, std::string(String), nullptr));
+    auto [It, Inserted] = Strings.try_emplace(TI);
+    if (Inserted)
+      It->second = std::make_tuple(++Index, std::string(String), nullptr);
   }
 
   StringRef find(TypeIndex TI) {



More information about the llvm-commits mailing list