Skip to content

[lldb] Avoid repeated hash lookups (NFC) #112301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Oct 15, 2024

@llvm/pr-subscribers-lldb

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) lldb/include/lldb/Breakpoint/StopPointSiteList.h (+2-8)
diff --git a/lldb/include/lldb/Breakpoint/StopPointSiteList.h b/lldb/include/lldb/Breakpoint/StopPointSiteList.h
index 9ff151fd01b69a..b929c37a12f092 100644
--- a/lldb/include/lldb/Breakpoint/StopPointSiteList.h
+++ b/lldb/include/lldb/Breakpoint/StopPointSiteList.h
@@ -38,16 +38,10 @@ template <typename StopPointSite> class StopPointSiteList {
   typename StopPointSite::SiteID Add(const StopPointSiteSP &site_sp) {
     lldb::addr_t site_load_addr = site_sp->GetLoadAddress();
     std::lock_guard<std::recursive_mutex> guard(m_mutex);
-    typename collection::iterator iter = m_site_list.find(site_load_addr);
-
     // Add site to the list.  However, if the element already exists in
     // the list, then we don't add it, and return InvalidSiteID.
-    if (iter == m_site_list.end()) {
-      m_site_list[site_load_addr] = site_sp;
-      return site_sp->GetID();
-    } else {
-      return UINT32_MAX;
-    }
+    bool inserted = m_site_list.try_emplace(site_load_addr, site_sp).second;
+    return inserted ? site_sp->GetID() : UINT32_MAX;
   }
 
   /// Standard Dump routine, doesn't do anything at present.

@kazutakahirata kazutakahirata merged commit bad04dc into llvm:main Oct 15, 2024
9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lldb branch October 15, 2024 04:34
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants