[Lldb-commits] [lldb] [lldb] Avoid repeated hash lookups (NFC) (PR #113024)

Kazu Hirata via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 18 22:15:29 PDT 2024


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

None

>From 02829d780f3032c86992a3ae6a13ab27017e5635 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 18 Oct 2024 09:10:44 -0700
Subject: [PATCH] [lldb] Avoid repeated hash lookups (NFC)

---
 lldb/source/Core/DataFileCache.cpp | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lldb/source/Core/DataFileCache.cpp b/lldb/source/Core/DataFileCache.cpp
index a8127efc1df064..ef0e07a8b03420 100644
--- a/lldb/source/Core/DataFileCache.cpp
+++ b/lldb/source/Core/DataFileCache.cpp
@@ -264,14 +264,12 @@ bool CacheSignature::Decode(const lldb_private::DataExtractor &data,
 }
 
 uint32_t ConstStringTable::Add(ConstString s) {
-  auto pos = m_string_to_offset.find(s);
-  if (pos != m_string_to_offset.end())
-    return pos->second;
-  const uint32_t offset = m_next_offset;
-  m_strings.push_back(s);
-  m_string_to_offset[s] = offset;
-  m_next_offset += s.GetLength() + 1;
-  return offset;
+  auto [pos, inserted] = m_string_to_offset.try_emplace(s, m_next_offset);
+  if (inserted) {
+    m_strings.push_back(s);
+    m_next_offset += s.GetLength() + 1;
+  }
+  return pos->second;
 }
 
 static const llvm::StringRef kStringTableIdentifier("STAB");



More information about the lldb-commits mailing list