[Lldb-commits] [lldb] 1a397ec - [lldb][NFCI] Remove use of ConstString from StructuredDataPlugin

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Fri Jun 23 10:37:50 PDT 2023


Author: Alex Langford
Date: 2023-06-23T10:29:52-07:00
New Revision: 1a397ecffdea64f5a521b4aac1fa4b98723dec22

URL: https://github.com/llvm/llvm-project/commit/1a397ecffdea64f5a521b4aac1fa4b98723dec22
DIFF: https://github.com/llvm/llvm-project/commit/1a397ecffdea64f5a521b4aac1fa4b98723dec22.diff

LOG: [lldb][NFCI] Remove use of ConstString from StructuredDataPlugin

The use of ConstString in StructuredDataPlugin is unneccessary as fast
comparisons are not neeeded for StructuredDataPlugins.

Differential Revision: https://reviews.llvm.org/D153482

Added: 
    

Modified: 
    lldb/include/lldb/Target/Process.h
    lldb/include/lldb/Target/StructuredDataPlugin.h
    lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
    lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
    lldb/source/Target/Process.cpp
    lldb/source/Target/StructuredDataPlugin.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 907ef50a7a61b..0f9b0c07df9bd 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -2833,7 +2833,7 @@ void PruneThreadPlans();
   ///
   ///     virtual void
   ///     HandleArrivalOfStructuredData(Process &process,
-  ///                                   ConstString type_name,
+  ///                                   llvm::StringRef type_name,
   ///                                   const StructuredData::ObjectSP
   ///                                   &object_sp)
   ///

diff  --git a/lldb/include/lldb/Target/StructuredDataPlugin.h b/lldb/include/lldb/Target/StructuredDataPlugin.h
index 09241d5281fb4..09111b1390505 100644
--- a/lldb/include/lldb/Target/StructuredDataPlugin.h
+++ b/lldb/include/lldb/Target/StructuredDataPlugin.h
@@ -64,7 +64,7 @@ class StructuredDataPlugin
   ///
   /// \return
   ///     true if the plugin supports the feature; otherwise, false.
-  virtual bool SupportsStructuredDataType(ConstString type_name) = 0;
+  virtual bool SupportsStructuredDataType(llvm::StringRef type_name) = 0;
 
   /// Handle the arrival of asynchronous structured data from the process.
   ///
@@ -92,7 +92,7 @@ class StructuredDataPlugin
   ///     key named "type" that must be a string value containing the
   ///     structured data type name.
   virtual void
-  HandleArrivalOfStructuredData(Process &process, ConstString type_name,
+  HandleArrivalOfStructuredData(Process &process, llvm::StringRef type_name,
                                 const StructuredData::ObjectSP &object_sp) = 0;
 
   /// Get a human-readable description of the contents of the data.
@@ -124,7 +124,7 @@ class StructuredDataPlugin
   /// \param[in] type_name
   ///     The name of the feature tag for the asynchronous structured data.
   ///     This is needed for plugins that support more than one feature.
-  virtual bool GetEnabled(ConstString type_name) const;
+  virtual bool GetEnabled(llvm::StringRef type_name) const;
 
   /// Allow the plugin to do work related to modules that loaded in the
   /// the corresponding process.

diff  --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
index 611e1506d8581..60e94b89e37e9 100644
--- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
+++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
@@ -875,9 +875,10 @@ class StatusCommand : public CommandObjectParsed {
           process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
       stream.Printf("Availability: %s\n",
                     plugin_sp ? "available" : "unavailable");
-      llvm::StringRef plugin_name = StructuredDataDarwinLog::GetStaticPluginName();
       const bool enabled =
-          plugin_sp ? plugin_sp->GetEnabled(ConstString(plugin_name)) : false;
+          plugin_sp ? plugin_sp->GetEnabled(
+                          StructuredDataDarwinLog::GetStaticPluginName())
+                    : false;
       stream.Printf("Enabled: %s\n", enabled ? "true" : "false");
     }
 
@@ -1057,12 +1058,12 @@ void StructuredDataDarwinLog::Terminate() {
 // StructuredDataPlugin API
 
 bool StructuredDataDarwinLog::SupportsStructuredDataType(
-    ConstString type_name) {
+    llvm::StringRef type_name) {
   return type_name == GetDarwinLogTypeName();
 }
 
 void StructuredDataDarwinLog::HandleArrivalOfStructuredData(
-    Process &process, ConstString type_name,
+    Process &process, llvm::StringRef type_name,
     const StructuredData::ObjectSP &object_sp) {
   Log *log = GetLog(LLDBLog::Process);
   if (log) {
@@ -1086,11 +1087,9 @@ void StructuredDataDarwinLog::HandleArrivalOfStructuredData(
 
   // Ignore any data that isn't for us.
   if (type_name != GetDarwinLogTypeName()) {
-    LLDB_LOGF(log,
-              "StructuredDataDarwinLog::%s() StructuredData type "
-              "expected to be %s but was %s, ignoring",
-              __FUNCTION__, GetDarwinLogTypeName().str().c_str(),
-              type_name.AsCString());
+    LLDB_LOG(log,
+             "StructuredData type expected to be {0} but was {1}, ignoring",
+             GetDarwinLogTypeName(), type_name);
     return;
   }
 
@@ -1200,11 +1199,10 @@ Status StructuredDataDarwinLog::GetDescription(
   return error;
 }
 
-bool StructuredDataDarwinLog::GetEnabled(ConstString type_name) const {
-  if (type_name.GetStringRef() == GetStaticPluginName())
+bool StructuredDataDarwinLog::GetEnabled(llvm::StringRef type_name) const {
+  if (type_name == GetStaticPluginName())
     return m_is_enabled;
-  else
-    return false;
+  return false;
 }
 
 void StructuredDataDarwinLog::SetEnabled(bool enabled) {

diff  --git a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
index 308fd82e9b12a..5b9abf3e603f2 100644
--- a/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
+++ b/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
@@ -50,16 +50,16 @@ class StructuredDataDarwinLog : public StructuredDataPlugin {
 
   // StructuredDataPlugin API
 
-  bool SupportsStructuredDataType(ConstString type_name) override;
+  bool SupportsStructuredDataType(llvm::StringRef type_name) override;
 
   void HandleArrivalOfStructuredData(
-      Process &process, ConstString type_name,
+      Process &process, llvm::StringRef type_name,
       const StructuredData::ObjectSP &object_sp) override;
 
   Status GetDescription(const StructuredData::ObjectSP &object_sp,
                         lldb_private::Stream &stream) override;
 
-  bool GetEnabled(ConstString type_name) const override;
+  bool GetEnabled(llvm::StringRef type_name) const override;
 
   void ModulesDidLoad(Process &process, ModuleList &module_list) override;
 

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 8542ffe91b56c..246279de086ae 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6070,7 +6070,7 @@ void Process::MapSupportedStructuredDataPlugins(
     // For any of the remaining type names, map any that this plugin supports.
     std::vector<llvm::StringRef> names_to_remove;
     for (llvm::StringRef type_name : type_names) {
-      if (plugin_sp->SupportsStructuredDataType(ConstString(type_name))) {
+      if (plugin_sp->SupportsStructuredDataType(type_name)) {
         m_structured_data_plugin_map.insert(
             std::make_pair(type_name, plugin_sp));
         names_to_remove.push_back(type_name);
@@ -6110,8 +6110,7 @@ bool Process::RouteAsyncStructuredData(
   }
 
   // Route the structured data to the plugin.
-  find_it->second->HandleArrivalOfStructuredData(*this, ConstString(type_name),
-                                                 object_sp);
+  find_it->second->HandleArrivalOfStructuredData(*this, type_name, object_sp);
   return true;
 }
 

diff  --git a/lldb/source/Target/StructuredDataPlugin.cpp b/lldb/source/Target/StructuredDataPlugin.cpp
index 20ed26a1a99a9..1b5894b5df4b6 100644
--- a/lldb/source/Target/StructuredDataPlugin.cpp
+++ b/lldb/source/Target/StructuredDataPlugin.cpp
@@ -32,7 +32,7 @@ StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp)
 
 StructuredDataPlugin::~StructuredDataPlugin() = default;
 
-bool StructuredDataPlugin::GetEnabled(ConstString type_name) const {
+bool StructuredDataPlugin::GetEnabled(llvm::StringRef type_name) const {
   // By default, plugins are always enabled.  Plugin authors should override
   // this if there is an enabled/disabled state for their plugin.
   return true;


        


More information about the lldb-commits mailing list