Author: Alex Langford Date: 2023-08-29T16:02:26-07:00 New Revision: 5d49c9ce65881467295fd5ef2022b60d6601e82f
URL: https://github.com/llvm/llvm-project/commit/5d49c9ce65881467295fd5ef2022b60d6601e82f DIFF: https://github.com/llvm/llvm-project/commit/5d49c9ce65881467295fd5ef2022b60d6601e82f.diff LOG: [lldb][NFCI] Remove StructuredData::Array::GetItemAtIndexAsString overloads with ConstString This is the next step in removing ConstString from StructuredData. There are StringRef overloads already, let's use those where we can. Differential Revision: https://reviews.llvm.org/D152870 Added: Modified: lldb/include/lldb/Utility/StructuredData.h lldb/source/Target/DynamicRegisterInfo.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Utility/StructuredData.h b/lldb/include/lldb/Utility/StructuredData.h index 3d306419340430..4133c0e036a22a 100644 --- a/lldb/include/lldb/Utility/StructuredData.h +++ b/lldb/include/lldb/Utility/StructuredData.h @@ -266,25 +266,6 @@ class StructuredData { 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); diff --git a/lldb/source/Target/DynamicRegisterInfo.cpp b/lldb/source/Target/DynamicRegisterInfo.cpp index ff255a8f82fd5d..f1f45e52918d37 100644 --- a/lldb/source/Target/DynamicRegisterInfo.cpp +++ b/lldb/source/Target/DynamicRegisterInfo.cpp @@ -144,21 +144,20 @@ llvm::Expected<uint32_t> DynamicRegisterInfo::ByteOffsetFromComposite( 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); @@ -206,9 +205,10 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, 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"); @@ -345,12 +345,12 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, 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]); @@ -359,7 +359,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, // 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)) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits