Skip to content

Commit dfac044

Browse files
[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.
1 parent bda8c50 commit dfac044

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

lldb/tools/lldb-dap/EventHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void SendProcessEvent(DAP &dap, LaunchMethod launch_method) {
9393
exe_fspec.GetPath(exe_path, sizeof(exe_path));
9494
llvm::json::Object event(CreateEventObject("process"));
9595
llvm::json::Object body;
96-
EmplaceSafeString(body, "name", std::string(exe_path));
96+
EmplaceSafeString(body, "name", exe_path);
9797
const auto pid = dap.target.GetProcess().GetProcessID();
9898
body.try_emplace("systemProcessId", (int64_t)pid);
9999
body.try_emplace("isLocalProcess", true);

lldb/tools/lldb-dap/Handler/EvaluateRequestHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void EvaluateRequestHandler::operator()(
205205
lldb::SBError error = value.GetError();
206206
const char *error_cstr = error.GetCString();
207207
if (error_cstr && error_cstr[0])
208-
EmplaceSafeString(response, "message", std::string(error_cstr));
208+
EmplaceSafeString(response, "message", error_cstr);
209209
else
210210
EmplaceSafeString(response, "message", "evaluate failed");
211211
} else {

lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void ExceptionInfoRequestHandler::operator()(
136136
if (!ObjectContainsKey(body, "description")) {
137137
char description[1024];
138138
if (thread.GetStopDescription(description, sizeof(description))) {
139-
EmplaceSafeString(body, "description", std::string(description));
139+
EmplaceSafeString(body, "description", description);
140140
}
141141
}
142142
body.try_emplace("breakMode", "always");

lldb/tools/lldb-dap/JSONUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ llvm::json::Value CreateThreadStopped(DAP &dap, lldb::SBThread &thread,
905905
if (!ObjectContainsKey(body, "description")) {
906906
char description[1024];
907907
if (thread.GetStopDescription(description, sizeof(description))) {
908-
EmplaceSafeString(body, "description", std::string(description));
908+
EmplaceSafeString(body, "description", description);
909909
}
910910
}
911911
// "threadCausedFocus" is used in tests to validate breaking behavior.

0 commit comments

Comments
 (0)