[lldb] Change interface of StructuredData::Array::GetItemAtIndexAsString (#71613)

This patch changes the interface of
StructuredData::Array::GetItemAtIndexAsString to return a
`std::optional<llvm::StringRef>` instead of taking an out parameter.
More generally, this commit serves as proposal that we change all of the
sibling APIs (`GetItemAtIndexAs`) to do the same thing. The reason this
isn't one giant patch is because it is rather unwieldy changing just one
of these, so if this is approved, I will do all of the other ones as
individual follow-ups.
This commit is contained in:
Alex Langford
2023-11-09 13:35:35 -08:00
committed by GitHub
parent fe98cce6a9
commit 1486264d5f
9 changed files with 63 additions and 71 deletions

View File

@@ -205,10 +205,9 @@ lldb::BreakpointSP Breakpoint::CreateFromStructuredData(
if (success && names_array) {
size_t num_names = names_array->GetSize();
for (size_t i = 0; i < num_names; i++) {
llvm::StringRef name;
Status error;
success = names_array->GetItemAtIndexAsString(i, name);
target.AddNameToBreakpoint(result_sp, name.str().c_str(), error);
if (std::optional<llvm::StringRef> maybe_name =
names_array->GetItemAtIndexAsString(i))
target.AddNameToBreakpoint(result_sp, *maybe_name, error);
}
}
@@ -238,11 +237,10 @@ bool Breakpoint::SerializedBreakpointMatchesNames(
size_t num_names = names_array->GetSize();
for (size_t i = 0; i < num_names; i++) {
llvm::StringRef name;
if (names_array->GetItemAtIndexAsString(i, name)) {
if (llvm::is_contained(names, name))
return true;
}
std::optional<llvm::StringRef> maybe_name =
names_array->GetItemAtIndexAsString(i);
if (maybe_name && llvm::is_contained(names, *maybe_name))
return true;
}
return false;
}