[lldb-dap] Avoid creating temporary instances of std::string (NFC) (#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.
This commit is contained in:
Kazu Hirata
2025-05-16 20:02:13 -07:00
committed by GitHub
parent bda8c502bf
commit dfac0445d0
4 changed files with 4 additions and 4 deletions

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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");

View File

@@ -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.