[Lldb-commits] [lldb] 867ee3b - [lldb][NFCI] Change type of Broadcaster's name

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 7 11:01:24 PDT 2023


Author: Alex Langford
Date: 2023-06-07T10:14:53-07:00
New Revision: 867ee3b8a76a78e02c56e78382e31bfd76fa468b

URL: https://github.com/llvm/llvm-project/commit/867ee3b8a76a78e02c56e78382e31bfd76fa468b
DIFF: https://github.com/llvm/llvm-project/commit/867ee3b8a76a78e02c56e78382e31bfd76fa468b.diff

LOG: [lldb][NFCI] Change type of Broadcaster's name

Broadcasters don't need their names in the StringPool. It doesn't
benefit from fast comparisons and doesn't benefit from uniqueness.

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

Added: 
    

Modified: 
    lldb/include/lldb/Utility/Broadcaster.h
    lldb/source/API/SBBroadcaster.cpp
    lldb/source/Core/ThreadedCommunication.cpp
    lldb/source/Utility/Broadcaster.cpp
    lldb/source/Utility/Event.cpp
    lldb/source/Utility/Listener.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Utility/Broadcaster.h b/lldb/include/lldb/Utility/Broadcaster.h
index 081e6ee5c883f..f9887566a1609 100644
--- a/lldb/include/lldb/Utility/Broadcaster.h
+++ b/lldb/include/lldb/Utility/Broadcaster.h
@@ -149,10 +149,12 @@ class Broadcaster {
 public:
   /// Construct with a broadcaster with a name.
   ///
+  /// \param[in] manager_sp
+  ///   A shared pointer to the BroadcasterManager that will manage this
+  ///   broadcaster.
   /// \param[in] name
-  ///     A NULL terminated C string that contains the name of the
-  ///     broadcaster object.
-  Broadcaster(lldb::BroadcasterManagerSP manager_sp, const char *name);
+  ///   A std::string of the name that this broadcaster will have.
+  Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name);
 
   /// Destructor.
   ///
@@ -213,11 +215,12 @@ class Broadcaster {
     return m_broadcaster_sp->AddListener(listener_sp, event_mask);
   }
 
-  /// Get the NULL terminated C string name of this Broadcaster object.
+  /// Get this broadcaster's name.
   ///
   /// \return
-  ///     The NULL terminated C string name of this Broadcaster.
-  ConstString GetBroadcasterName() { return m_broadcaster_name; }
+  ///     A reference to a constant std::string containing the name of the
+  ///     broadcaster.
+  const std::string &GetBroadcasterName() { return m_broadcaster_name; }
 
   /// Get the event name(s) for one or more event bits.
   ///
@@ -352,8 +355,8 @@ class Broadcaster {
     uint32_t AddListener(const lldb::ListenerSP &listener_sp,
                          uint32_t event_mask);
 
-    const char *GetBroadcasterName() const {
-      return m_broadcaster.GetBroadcasterName().AsCString();
+    const std::string &GetBroadcasterName() const {
+      return m_broadcaster.GetBroadcasterName();
     }
 
     Broadcaster *GetBroadcaster();
@@ -443,7 +446,7 @@ class Broadcaster {
   lldb::BroadcasterManagerSP m_manager_sp;
 
   /// The name of this broadcaster object.
-  const ConstString m_broadcaster_name;
+  const std::string m_broadcaster_name;
 
   Broadcaster(const Broadcaster &) = delete;
   const Broadcaster &operator=(const Broadcaster &) = delete;

diff  --git a/lldb/source/API/SBBroadcaster.cpp b/lldb/source/API/SBBroadcaster.cpp
index 58920931bc5fc..6e34b2f71b824 100644
--- a/lldb/source/API/SBBroadcaster.cpp
+++ b/lldb/source/API/SBBroadcaster.cpp
@@ -92,7 +92,7 @@ const char *SBBroadcaster::GetName() const {
   LLDB_INSTRUMENT_VA(this);
 
   if (m_opaque_ptr)
-    return m_opaque_ptr->GetBroadcasterName().GetCString();
+    return ConstString(m_opaque_ptr->GetBroadcasterName()).GetCString();
   return nullptr;
 }
 

diff  --git a/lldb/source/Core/ThreadedCommunication.cpp b/lldb/source/Core/ThreadedCommunication.cpp
index d547c858f0f57..ec4b0806a80e4 100644
--- a/lldb/source/Core/ThreadedCommunication.cpp
+++ b/lldb/source/Core/ThreadedCommunication.cpp
@@ -57,7 +57,7 @@ ThreadedCommunication::ThreadedCommunication(const char *name)
 ThreadedCommunication::~ThreadedCommunication() {
   LLDB_LOG(GetLog(LLDBLog::Object | LLDBLog::Communication),
            "{0} ThreadedCommunication::~ThreadedCommunication (name = {1})",
-           this, GetBroadcasterName().AsCString());
+           this, GetBroadcasterName());
 }
 
 void ThreadedCommunication::Clear() {

diff  --git a/lldb/source/Utility/Broadcaster.cpp b/lldb/source/Utility/Broadcaster.cpp
index 58e393863b5a5..c9ecd4a7d2a91 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -23,9 +23,9 @@
 using namespace lldb;
 using namespace lldb_private;
 
-Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name)
+Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, std::string name)
     : m_broadcaster_sp(std::make_shared<BroadcasterImpl>(*this)),
-      m_manager_sp(std::move(manager_sp)), m_broadcaster_name(name) {
+      m_manager_sp(std::move(manager_sp)), m_broadcaster_name(std::move(name)) {
   Log *log = GetLog(LLDBLog::Object);
   LLDB_LOG(log, "{0} Broadcaster::Broadcaster(\"{1}\")",
            static_cast<void *>(this), GetBroadcasterName());
@@ -215,12 +215,12 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp,
   if (log) {
     StreamString event_description;
     event_sp->Dump(&event_description);
-    LLDB_LOGF(log,
-              "%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, "
-              "unique =%i) hijack = %p",
-              static_cast<void *>(this), GetBroadcasterName(),
-              event_description.GetData(), unique,
-              static_cast<void *>(hijacking_listener_sp.get()));
+    LLDB_LOG(log,
+             "{0:x} Broadcaster(\"{1}\")::BroadcastEvent (event_sp = {2}, "
+             "unique={3}) hijack = {4:x}",
+             static_cast<void *>(this), GetBroadcasterName(),
+             event_description.GetData(), unique,
+             static_cast<void *>(hijacking_listener_sp.get()));
   }
 
   if (hijacking_listener_sp) {

diff  --git a/lldb/source/Utility/Event.cpp b/lldb/source/Utility/Event.cpp
index 291e191736041..efab7600998f1 100644
--- a/lldb/source/Utility/Event.cpp
+++ b/lldb/source/Utility/Event.cpp
@@ -58,13 +58,13 @@ void Event::Dump(Stream *s) const {
       s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x (%s), data = ",
                 static_cast<const void *>(this),
                 static_cast<void *>(broadcaster),
-                broadcaster->GetBroadcasterName().GetCString(), m_type,
+                broadcaster->GetBroadcasterName().c_str(), m_type,
                 event_name.GetData());
     else
       s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x, data = ",
                 static_cast<const void *>(this),
                 static_cast<void *>(broadcaster),
-                broadcaster->GetBroadcasterName().GetCString(), m_type);
+                broadcaster->GetBroadcasterName().c_str(), m_type);
   } else
     s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ",
               static_cast<const void *>(this), m_type);

diff  --git a/lldb/source/Utility/Listener.cpp b/lldb/source/Utility/Listener.cpp
index 2286827c51385..060fc2b1cedf1 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -234,7 +234,7 @@ class EventMatcher {
 
     if (m_broadcaster_names) {
       bool found_source = false;
-      ConstString event_broadcaster_name =
+      const llvm::StringRef event_broadcaster_name =
           event_sp->GetBroadcaster()->GetBroadcasterName();
       for (uint32_t i = 0; i < m_num_broadcaster_names; ++i) {
         if (m_broadcaster_names[i] == event_broadcaster_name) {


        


More information about the lldb-commits mailing list