https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/140325
EmplaceSafeString accepts StringRef for the last parameter, str, and then internally creates a copy of str via StringRef::str or llvm::json::fixUTF8, so caller do not need to create their own temporary instances of std::string. >From efaef78da4a3cdb62db966f79692414c07a172c1 Mon Sep 17 00:00:00 2001 From: Kazu Hirata <k...@google.com> Date: Fri, 16 May 2025 17:59:35 -0700 Subject: [PATCH] [lldb-dap] Avoid creating temporary instances of std::string (NFC) EmplaceSafeString accepts StringRef for the last parameter, str, and then internally creates a copy of str via StringRef::str or llvm::json::fixUTF8, so caller do not need to create their own temporary instances of std::string. --- lldb/tools/lldb-dap/EventHelper.cpp | 2 +- lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp | 2 +- lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp | 2 +- lldb/tools/lldb-dap/JSONUtils.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lldb/tools/lldb-dap/EventHelper.cpp b/lldb/tools/lldb-dap/EventHelper.cpp index ed2d8700c26b0..c698084836e2f 100644 --- a/lldb/tools/lldb-dap/EventHelper.cpp +++ b/lldb/tools/lldb-dap/EventHelper.cpp @@ -93,7 +93,7 @@ void SendProcessEvent(DAP &dap, LaunchMethod launch_method) { exe_fspec.GetPath(exe_path, sizeof(exe_path)); llvm::json::Object event(CreateEventObject("process")); llvm::json::Object body; - EmplaceSafeString(body, "name", std::string(exe_path)); + EmplaceSafeString(body, "name", exe_path); const auto pid = dap.target.GetProcess().GetProcessID(); body.try_emplace("systemProcessId", (int64_t)pid); body.try_emplace("isLocalProcess", true); diff --git a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp index 5ce133c33b7e1..e1556846dff19 100644 --- a/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp @@ -205,7 +205,7 @@ void EvaluateRequestHandler::operator()( lldb::SBError error = value.GetError(); const char *error_cstr = error.GetCString(); if (error_cstr && error_cstr[0]) - EmplaceSafeString(response, "message", std::string(error_cstr)); + EmplaceSafeString(response, "message", error_cstr); else EmplaceSafeString(response, "message", "evaluate failed"); } else { diff --git a/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp index 924ea63ed1593..c1c2adb32a510 100644 --- a/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp @@ -136,7 +136,7 @@ void ExceptionInfoRequestHandler::operator()( if (!ObjectContainsKey(body, "description")) { char description[1024]; if (thread.GetStopDescription(description, sizeof(description))) { - EmplaceSafeString(body, "description", std::string(description)); + EmplaceSafeString(body, "description", description); } } body.try_emplace("breakMode", "always"); diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp index a8bd672583a5d..714947a4d3b9c 100644 --- a/lldb/tools/lldb-dap/JSONUtils.cpp +++ b/lldb/tools/lldb-dap/JSONUtils.cpp @@ -905,7 +905,7 @@ llvm::json::Value CreateThreadStopped(DAP &dap, lldb::SBThread &thread, if (!ObjectContainsKey(body, "description")) { char description[1024]; if (thread.GetStopDescription(description, sizeof(description))) { - EmplaceSafeString(body, "description", std::string(description)); + EmplaceSafeString(body, "description", description); } } // "threadCausedFocus" is used in tests to validate breaking behavior. _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits