Skip to content

Commit 867ee3b

Browse files
committed
[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
1 parent cfdea8f commit 867ee3b

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

lldb/include/lldb/Utility/Broadcaster.h

+12-9
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ class Broadcaster {
149149
public:
150150
/// Construct with a broadcaster with a name.
151151
///
152+
/// \param[in] manager_sp
153+
/// A shared pointer to the BroadcasterManager that will manage this
154+
/// broadcaster.
152155
/// \param[in] name
153-
/// A NULL terminated C string that contains the name of the
154-
/// broadcaster object.
155-
Broadcaster(lldb::BroadcasterManagerSP manager_sp, const char *name);
156+
/// A std::string of the name that this broadcaster will have.
157+
Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name);
156158

157159
/// Destructor.
158160
///
@@ -213,11 +215,12 @@ class Broadcaster {
213215
return m_broadcaster_sp->AddListener(listener_sp, event_mask);
214216
}
215217

216-
/// Get the NULL terminated C string name of this Broadcaster object.
218+
/// Get this broadcaster's name.
217219
///
218220
/// \return
219-
/// The NULL terminated C string name of this Broadcaster.
220-
ConstString GetBroadcasterName() { return m_broadcaster_name; }
221+
/// A reference to a constant std::string containing the name of the
222+
/// broadcaster.
223+
const std::string &GetBroadcasterName() { return m_broadcaster_name; }
221224

222225
/// Get the event name(s) for one or more event bits.
223226
///
@@ -352,8 +355,8 @@ class Broadcaster {
352355
uint32_t AddListener(const lldb::ListenerSP &listener_sp,
353356
uint32_t event_mask);
354357

355-
const char *GetBroadcasterName() const {
356-
return m_broadcaster.GetBroadcasterName().AsCString();
358+
const std::string &GetBroadcasterName() const {
359+
return m_broadcaster.GetBroadcasterName();
357360
}
358361

359362
Broadcaster *GetBroadcaster();
@@ -443,7 +446,7 @@ class Broadcaster {
443446
lldb::BroadcasterManagerSP m_manager_sp;
444447

445448
/// The name of this broadcaster object.
446-
const ConstString m_broadcaster_name;
449+
const std::string m_broadcaster_name;
447450

448451
Broadcaster(const Broadcaster &) = delete;
449452
const Broadcaster &operator=(const Broadcaster &) = delete;

lldb/source/API/SBBroadcaster.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const char *SBBroadcaster::GetName() const {
9292
LLDB_INSTRUMENT_VA(this);
9393

9494
if (m_opaque_ptr)
95-
return m_opaque_ptr->GetBroadcasterName().GetCString();
95+
return ConstString(m_opaque_ptr->GetBroadcasterName()).GetCString();
9696
return nullptr;
9797
}
9898

lldb/source/Core/ThreadedCommunication.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ThreadedCommunication::ThreadedCommunication(const char *name)
5757
ThreadedCommunication::~ThreadedCommunication() {
5858
LLDB_LOG(GetLog(LLDBLog::Object | LLDBLog::Communication),
5959
"{0} ThreadedCommunication::~ThreadedCommunication (name = {1})",
60-
this, GetBroadcasterName().AsCString());
60+
this, GetBroadcasterName());
6161
}
6262

6363
void ThreadedCommunication::Clear() {

lldb/source/Utility/Broadcaster.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
using namespace lldb;
2424
using namespace lldb_private;
2525

26-
Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name)
26+
Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, std::string name)
2727
: m_broadcaster_sp(std::make_shared<BroadcasterImpl>(*this)),
28-
m_manager_sp(std::move(manager_sp)), m_broadcaster_name(name) {
28+
m_manager_sp(std::move(manager_sp)), m_broadcaster_name(std::move(name)) {
2929
Log *log = GetLog(LLDBLog::Object);
3030
LLDB_LOG(log, "{0} Broadcaster::Broadcaster(\"{1}\")",
3131
static_cast<void *>(this), GetBroadcasterName());
@@ -215,12 +215,12 @@ void Broadcaster::BroadcasterImpl::PrivateBroadcastEvent(EventSP &event_sp,
215215
if (log) {
216216
StreamString event_description;
217217
event_sp->Dump(&event_description);
218-
LLDB_LOGF(log,
219-
"%p Broadcaster(\"%s\")::BroadcastEvent (event_sp = {%s}, "
220-
"unique =%i) hijack = %p",
221-
static_cast<void *>(this), GetBroadcasterName(),
222-
event_description.GetData(), unique,
223-
static_cast<void *>(hijacking_listener_sp.get()));
218+
LLDB_LOG(log,
219+
"{0:x} Broadcaster(\"{1}\")::BroadcastEvent (event_sp = {2}, "
220+
"unique={3}) hijack = {4:x}",
221+
static_cast<void *>(this), GetBroadcasterName(),
222+
event_description.GetData(), unique,
223+
static_cast<void *>(hijacking_listener_sp.get()));
224224
}
225225

226226
if (hijacking_listener_sp) {

lldb/source/Utility/Event.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ void Event::Dump(Stream *s) const {
5858
s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x (%s), data = ",
5959
static_cast<const void *>(this),
6060
static_cast<void *>(broadcaster),
61-
broadcaster->GetBroadcasterName().GetCString(), m_type,
61+
broadcaster->GetBroadcasterName().c_str(), m_type,
6262
event_name.GetData());
6363
else
6464
s->Printf("%p Event: broadcaster = %p (%s), type = 0x%8.8x, data = ",
6565
static_cast<const void *>(this),
6666
static_cast<void *>(broadcaster),
67-
broadcaster->GetBroadcasterName().GetCString(), m_type);
67+
broadcaster->GetBroadcasterName().c_str(), m_type);
6868
} else
6969
s->Printf("%p Event: broadcaster = NULL, type = 0x%8.8x, data = ",
7070
static_cast<const void *>(this), m_type);

lldb/source/Utility/Listener.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class EventMatcher {
234234

235235
if (m_broadcaster_names) {
236236
bool found_source = false;
237-
ConstString event_broadcaster_name =
237+
const llvm::StringRef event_broadcaster_name =
238238
event_sp->GetBroadcaster()->GetBroadcasterName();
239239
for (uint32_t i = 0; i < m_num_broadcaster_names; ++i) {
240240
if (m_broadcaster_names[i] == event_broadcaster_name) {

0 commit comments

Comments
 (0)