[Lldb-commits] [lldb] d839c06 - [lldb] Avoid repeated map lookups (NFC) (#123892)

via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 21 23:48:56 PST 2025


Author: Kazu Hirata
Date: 2025-01-21T23:48:52-08:00
New Revision: d839c06719128700bdd033361b20aa6899f6620a

URL: https://github.com/llvm/llvm-project/commit/d839c06719128700bdd033361b20aa6899f6620a
DIFF: https://github.com/llvm/llvm-project/commit/d839c06719128700bdd033361b20aa6899f6620a.diff

LOG: [lldb] Avoid repeated map lookups (NFC) (#123892)

Added: 
    

Modified: 
    lldb/source/Target/Process.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 142dd882aceeca..c594fd94c9904b 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -1294,17 +1294,12 @@ bool Process::HasAssignedIndexIDToThread(uint64_t thread_id) {
 }
 
 uint32_t Process::AssignIndexIDToThread(uint64_t thread_id) {
-  uint32_t result = 0;
-  std::map<uint64_t, uint32_t>::iterator iterator =
-      m_thread_id_to_index_id_map.find(thread_id);
-  if (iterator == m_thread_id_to_index_id_map.end()) {
-    result = ++m_thread_index_id;
-    m_thread_id_to_index_id_map[thread_id] = result;
-  } else {
-    result = iterator->second;
-  }
+  auto [iterator, inserted] =
+      m_thread_id_to_index_id_map.try_emplace(thread_id, m_thread_index_id + 1);
+  if (inserted)
+    ++m_thread_index_id;
 
-  return result;
+  return iterator->second;
 }
 
 StateType Process::GetState() {


        


More information about the lldb-commits mailing list