[Lldb-commits] [lldb] [lldb-dap] Use heterogenous lookups with std::map (NFC) (PR #115590)

Kazu Hirata via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 8 23:30:27 PST 2024


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

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


>From 1ae19de089b41bda586403d6379e6f644654e4ba Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 8 Nov 2024 07:46:06 -0800
Subject: [PATCH] [lldb-dap] Use heterogenous lookups with std::map (NFC)

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
 lldb/tools/lldb-dap/DAP.cpp | 2 +-
 lldb/tools/lldb-dap/DAP.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 647e28080b6339..e45f9bf359e5bf 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -692,7 +692,7 @@ bool DAP::HandleObject(const llvm::json::Object &object) {
   const auto packet_type = GetString(object, "type");
   if (packet_type == "request") {
     const auto command = GetString(object, "command");
-    auto handler_pos = request_handlers.find(std::string(command));
+    auto handler_pos = request_handlers.find(command);
     if (handler_pos != request_handlers.end()) {
       handler_pos->second(object);
       return true; // Success
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index dab4ce44ab202c..1641a58c7dbd06 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -171,7 +171,7 @@ struct DAP {
   // the old process here so we can detect this case and keep running.
   lldb::pid_t restarting_process_id;
   bool configuration_done_sent;
-  std::map<std::string, RequestCallback> request_handlers;
+  std::map<std::string, RequestCallback, std::less<>> request_handlers;
   bool waiting_for_run_in_terminal;
   ProgressEventReporter progress_event_reporter;
   // Keep track of the last stop thread index IDs as threads won't go away



More information about the lldb-commits mailing list