[lldb][NFC] avoid unnecessary roundtrips between different string types

The amount of roundtrips between StringRefs, ConstStrings and std::strings is
getting a bit out of hand, this patch avoid the unnecessary roundtrips.

Reviewed By: wallace, aprantl

Differential Revision: https://reviews.llvm.org/D112863
This commit is contained in:
Xu Jun
2021-11-01 22:14:48 -07:00
committed by Walter Erquinigo
parent fe19ae352c
commit dfd499a61c
9 changed files with 51 additions and 62 deletions

View File

@@ -214,8 +214,8 @@ SBStructuredData SBTarget::GetStatistics() {
if (!target_sp)
return LLDB_RECORD_RESULT(data);
std::string json_str =
llvm::formatv("{0:2}",
DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
llvm::formatv("{0:2}",
DebuggerStats::ReportStatistics(target_sp->GetDebugger(),
target_sp.get())).str();
data.m_impl_up->SetObjectSP(StructuredData::ParseJSON(json_str));
return LLDB_RECORD_RESULT(data);
@@ -1586,13 +1586,13 @@ void SBTarget::AppendImageSearchPath(const char *from, const char *to,
if (!target_sp)
return error.SetErrorString("invalid target");
const ConstString csFrom(from), csTo(to);
if (!csFrom)
llvm::StringRef srFrom = from, srTo = to;
if (srFrom.empty())
return error.SetErrorString("<from> path can't be empty");
if (!csTo)
if (srTo.empty())
return error.SetErrorString("<to> path can't be empty");
target_sp->GetImageSearchPathList().Append(csFrom, csTo, true);
target_sp->GetImageSearchPathList().Append(srFrom, srTo, true);
}
lldb::SBModule SBTarget::AddModule(const char *path, const char *triple,