bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, fdeazeve, jingham.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

In an effort to keep the ConstString StringPool small, I plan on
removing use of ConstString in StructuredData. The only class that
really uses it is StructuredData::Dictionary.

This one was fairly easy to remove, I plan on removing the others in
follow-up changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152597

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
@@ -238,17 +238,20 @@
     std::vector<uint32_t> invalidate_regs;
     memset(&reg_info, 0, sizeof(reg_info));
 
-    ConstString name_val;
-    ConstString alt_name_val;
-    if (!reg_info_dict->GetValueForKeyAsString("name", name_val, nullptr)) {
+    llvm::StringRef name_val;
+    if (!reg_info_dict->GetValueForKeyAsString("name", name_val)) {
       Clear();
       printf("error: registers must have valid names and offsets\n");
       reg_info_dict->DumpToStdout();
       return 0;
     }
-    reg_info.name = name_val.GetCString();
-    reg_info_dict->GetValueForKeyAsString("alt-name", alt_name_val, nullptr);
-    reg_info.alt_name = alt_name_val.GetCString();
+    reg_info.name = ConstString(name_val).GetCString();
+
+    llvm::StringRef alt_name_val;
+    if (reg_info_dict->GetValueForKeyAsString("alt-name", alt_name_val))
+      reg_info.alt_name = ConstString(alt_name_val).GetCString();
+    else
+      reg_info.alt_name = nullptr;
 
     llvm::Expected<uint32_t> byte_offset =
         ByteOffsetFromRegInfoDict(i, *reg_info_dict, byte_order);
Index: lldb/include/lldb/Utility/StructuredData.h
===================================================================
--- lldb/include/lldb/Utility/StructuredData.h
+++ lldb/include/lldb/Utility/StructuredData.h
@@ -536,26 +536,6 @@
       return success;
     }
 
-    bool GetValueForKeyAsString(llvm::StringRef key,
-                                ConstString &result) const {
-      ObjectSP value_sp = GetValueForKey(key);
-      if (value_sp.get()) {
-        if (auto string_value = value_sp->GetAsString()) {
-          result = ConstString(string_value->GetValue());
-          return true;
-        }
-      }
-      return false;
-    }
-
-    bool GetValueForKeyAsString(llvm::StringRef key, ConstString &result,
-                                const char *default_val) const {
-      bool success = GetValueForKeyAsString(key, result);
-      if (!success)
-        result.SetCString(default_val);
-      return success;
-    }
-
     bool GetValueForKeyAsDictionary(llvm::StringRef key,
                                     Dictionary *&result) const {
       result = nullptr;


Index: lldb/source/Target/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Target/DynamicRegisterInfo.cpp
+++ lldb/source/Target/DynamicRegisterInfo.cpp
@@ -238,17 +238,20 @@
     std::vector<uint32_t> invalidate_regs;
     memset(&reg_info, 0, sizeof(reg_info));
 
-    ConstString name_val;
-    ConstString alt_name_val;
-    if (!reg_info_dict->GetValueForKeyAsString("name", name_val, nullptr)) {
+    llvm::StringRef name_val;
+    if (!reg_info_dict->GetValueForKeyAsString("name", name_val)) {
       Clear();
       printf("error: registers must have valid names and offsets\n");
       reg_info_dict->DumpToStdout();
       return 0;
     }
-    reg_info.name = name_val.GetCString();
-    reg_info_dict->GetValueForKeyAsString("alt-name", alt_name_val, nullptr);
-    reg_info.alt_name = alt_name_val.GetCString();
+    reg_info.name = ConstString(name_val).GetCString();
+
+    llvm::StringRef alt_name_val;
+    if (reg_info_dict->GetValueForKeyAsString("alt-name", alt_name_val))
+      reg_info.alt_name = ConstString(alt_name_val).GetCString();
+    else
+      reg_info.alt_name = nullptr;
 
     llvm::Expected<uint32_t> byte_offset =
         ByteOffsetFromRegInfoDict(i, *reg_info_dict, byte_order);
Index: lldb/include/lldb/Utility/StructuredData.h
===================================================================
--- lldb/include/lldb/Utility/StructuredData.h
+++ lldb/include/lldb/Utility/StructuredData.h
@@ -536,26 +536,6 @@
       return success;
     }
 
-    bool GetValueForKeyAsString(llvm::StringRef key,
-                                ConstString &result) const {
-      ObjectSP value_sp = GetValueForKey(key);
-      if (value_sp.get()) {
-        if (auto string_value = value_sp->GetAsString()) {
-          result = ConstString(string_value->GetValue());
-          return true;
-        }
-      }
-      return false;
-    }
-
-    bool GetValueForKeyAsString(llvm::StringRef key, ConstString &result,
-                                const char *default_val) const {
-      bool success = GetValueForKeyAsString(key, result);
-      if (!success)
-        result.SetCString(default_val);
-      return success;
-    }
-
     bool GetValueForKeyAsDictionary(llvm::StringRef key,
                                     Dictionary *&result) const {
       result = nullptr;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH]... Alex Langford via Phabricator via lldb-commits

Reply via email to