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

via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 18 22:16:09 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/113024.diff


1 Files Affected:

- (modified) lldb/source/Core/DataFileCache.cpp (+6-8) 


``````````diff
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");

``````````

</details>


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


More information about the lldb-commits mailing list