[Lldb-commits] [PATCH] D152870: [lldb][NFCI] Remove StructuredData::Array::GetItemAtIndexAsString overloads with ConstString
Alex Langford via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 13 17:26:27 PDT 2023
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, jingham.
Herald added a subscriber: arphaman.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
This is the next step in removing ConstString from StructuredData. There
are StringRef overloads already, let's use those where we can.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152870
Files:
lldb/include/lldb/Utility/StructuredData.h
lldb/source/Target/DynamicRegisterInfo.cpp
Index: lldb/source/Target/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ lldb/source/Target/DynamicRegisterInfo.cpp
@@ -137,21 +137,20 @@
uint32_t composite_offset = UINT32_MAX;
for (uint32_t composite_idx = 0; composite_idx < num_composite_regs;
++composite_idx) {
- ConstString composite_reg_name;
- if (!composite_reg_list.GetItemAtIndexAsString(composite_idx,
- composite_reg_name, nullptr))
+ llvm::StringRef composite_reg_name;
+ if (!composite_reg_list.GetItemAtIndexAsString(composite_idx, composite_reg_name))
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"\"composite\" list value is not a Python string at index %d",
composite_idx);
const RegisterInfo *composite_reg_info =
- GetRegisterInfo(composite_reg_name.GetStringRef());
+ GetRegisterInfo(composite_reg_name);
if (!composite_reg_info)
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"failed to find composite register by name: \"%s\"",
- composite_reg_name.GetCString());
+ composite_reg_name.str().c_str());
composite_offset =
std::min(composite_offset, composite_reg_info->byte_offset);
@@ -199,9 +198,10 @@
if (dict.GetValueForKeyAsArray("sets", sets)) {
const uint32_t num_sets = sets->GetSize();
for (uint32_t i = 0; i < num_sets; ++i) {
- ConstString set_name;
- if (sets->GetItemAtIndexAsString(i, set_name) && !set_name.IsEmpty()) {
- m_sets.push_back({set_name.AsCString(), nullptr, 0, nullptr});
+ llvm::StringRef set_name;
+ if (sets->GetItemAtIndexAsString(i, set_name) && !set_name.empty()) {
+ m_sets.push_back(
+ {ConstString(set_name).AsCString(), nullptr, 0, nullptr});
} else {
Clear();
printf("error: register sets must have valid names\n");
@@ -338,12 +338,12 @@
const size_t num_regs = invalidate_reg_list->GetSize();
if (num_regs > 0) {
for (uint32_t idx = 0; idx < num_regs; ++idx) {
- ConstString invalidate_reg_name;
+ llvm::StringRef invalidate_reg_name;
uint64_t invalidate_reg_num;
if (invalidate_reg_list->GetItemAtIndexAsString(
idx, invalidate_reg_name)) {
const RegisterInfo *invalidate_reg_info =
- GetRegisterInfo(invalidate_reg_name.GetStringRef());
+ GetRegisterInfo(invalidate_reg_name);
if (invalidate_reg_info) {
m_invalidate_regs_map[i].push_back(
invalidate_reg_info->kinds[eRegisterKindLLDB]);
@@ -352,7 +352,7 @@
// format
printf("error: failed to find a 'invalidate-regs' register for "
"\"%s\" while parsing register \"%s\"\n",
- invalidate_reg_name.GetCString(), reg_info.name);
+ invalidate_reg_name.str().c_str(), reg_info.name);
}
} else if (invalidate_reg_list->GetItemAtIndexAsInteger(
idx, invalidate_reg_num)) {
Index: lldb/include/lldb/Utility/StructuredData.h
===================================================================
--- lldb/include/lldb/Utility/StructuredData.h
+++ lldb/include/lldb/Utility/StructuredData.h
@@ -266,25 +266,6 @@
return success;
}
- bool GetItemAtIndexAsString(size_t idx, ConstString &result) const {
- ObjectSP value_sp = GetItemAtIndex(idx);
- if (value_sp.get()) {
- if (auto string_value = value_sp->GetAsString()) {
- result = ConstString(string_value->GetValue());
- return true;
- }
- }
- return false;
- }
-
- bool GetItemAtIndexAsString(size_t idx, ConstString &result,
- const char *default_val) const {
- bool success = GetItemAtIndexAsString(idx, result);
- if (!success)
- result.SetCString(default_val);
- return success;
- }
-
bool GetItemAtIndexAsDictionary(size_t idx, Dictionary *&result) const {
result = nullptr;
ObjectSP value_sp = GetItemAtIndex(idx);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152870.531122.patch
Type: text/x-patch
Size: 4310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230614/d1575fe8/attachment-0001.bin>
More information about the lldb-commits
mailing list