forked from OSchip/llvm-project
[Utility] Avoid a few unnecessary copies (NFC)
Avoid unnecessary copies by either passing by const-reference or moving the argument. llvm-svn: 361544
This commit is contained in:
parent
f81ebfb045
commit
266b65f840
|
@ -51,7 +51,7 @@ public:
|
|||
// Tell whether this BroadcastEventSpec is contained in in_spec. That is: (a)
|
||||
// the two spec's share the same broadcaster class (b) the event bits of this
|
||||
// spec are wholly contained in those of in_spec.
|
||||
bool IsContainedIn(BroadcastEventSpec in_spec) const {
|
||||
bool IsContainedIn(const BroadcastEventSpec &in_spec) const {
|
||||
if (m_broadcaster_class != in_spec.GetBroadcasterClass())
|
||||
return false;
|
||||
uint32_t in_bits = in_spec.GetEventBits();
|
||||
|
@ -90,12 +90,13 @@ public:
|
|||
~BroadcasterManager() = default;
|
||||
|
||||
uint32_t RegisterListenerForEvents(const lldb::ListenerSP &listener_sp,
|
||||
BroadcastEventSpec event_spec);
|
||||
const BroadcastEventSpec &event_spec);
|
||||
|
||||
bool UnregisterListenerForEvents(const lldb::ListenerSP &listener_sp,
|
||||
BroadcastEventSpec event_spec);
|
||||
const BroadcastEventSpec &event_spec);
|
||||
|
||||
lldb::ListenerSP GetListenerForEventSpec(BroadcastEventSpec event_spec) const;
|
||||
lldb::ListenerSP
|
||||
GetListenerForEventSpec(const BroadcastEventSpec &event_spec) const;
|
||||
|
||||
void SignUpListenersForBroadcaster(Broadcaster &broadcaster);
|
||||
|
||||
|
@ -123,7 +124,7 @@ private:
|
|||
|
||||
~BroadcasterClassMatches() = default;
|
||||
|
||||
bool operator()(const event_listener_key input) const {
|
||||
bool operator()(const event_listener_key &input) const {
|
||||
return (input.first.GetBroadcasterClass() == m_broadcaster_class);
|
||||
}
|
||||
|
||||
|
@ -133,12 +134,12 @@ private:
|
|||
|
||||
class BroadcastEventSpecMatches {
|
||||
public:
|
||||
BroadcastEventSpecMatches(BroadcastEventSpec broadcaster_spec)
|
||||
BroadcastEventSpecMatches(const BroadcastEventSpec &broadcaster_spec)
|
||||
: m_broadcaster_spec(broadcaster_spec) {}
|
||||
|
||||
~BroadcastEventSpecMatches() = default;
|
||||
|
||||
bool operator()(const event_listener_key input) const {
|
||||
bool operator()(const event_listener_key &input) const {
|
||||
return (input.first.IsContainedIn(m_broadcaster_spec));
|
||||
}
|
||||
|
||||
|
@ -148,13 +149,14 @@ private:
|
|||
|
||||
class ListenerMatchesAndSharedBits {
|
||||
public:
|
||||
explicit ListenerMatchesAndSharedBits(BroadcastEventSpec broadcaster_spec,
|
||||
const lldb::ListenerSP listener_sp)
|
||||
explicit ListenerMatchesAndSharedBits(
|
||||
const BroadcastEventSpec &broadcaster_spec,
|
||||
const lldb::ListenerSP &listener_sp)
|
||||
: m_broadcaster_spec(broadcaster_spec), m_listener_sp(listener_sp) {}
|
||||
|
||||
~ListenerMatchesAndSharedBits() = default;
|
||||
|
||||
bool operator()(const event_listener_key input) const {
|
||||
bool operator()(const event_listener_key &input) const {
|
||||
return (input.first.GetBroadcasterClass() ==
|
||||
m_broadcaster_spec.GetBroadcasterClass() &&
|
||||
(input.first.GetEventBits() &
|
||||
|
@ -169,12 +171,12 @@ private:
|
|||
|
||||
class ListenerMatches {
|
||||
public:
|
||||
explicit ListenerMatches(const lldb::ListenerSP in_listener_sp)
|
||||
explicit ListenerMatches(const lldb::ListenerSP &in_listener_sp)
|
||||
: m_listener_sp(in_listener_sp) {}
|
||||
|
||||
~ListenerMatches() = default;
|
||||
|
||||
bool operator()(const event_listener_key input) const {
|
||||
bool operator()(const event_listener_key &input) const {
|
||||
if (input.second == m_listener_sp)
|
||||
return true;
|
||||
else
|
||||
|
@ -192,14 +194,14 @@ private:
|
|||
|
||||
~ListenerMatchesPointer() = default;
|
||||
|
||||
bool operator()(const event_listener_key input) const {
|
||||
bool operator()(const event_listener_key &input) const {
|
||||
if (input.second.get() == m_listener)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator()(const lldb::ListenerSP input) const {
|
||||
bool operator()(const lldb::ListenerSP &input) const {
|
||||
if (input.get() == m_listener)
|
||||
return true;
|
||||
else
|
||||
|
|
|
@ -58,10 +58,11 @@ public:
|
|||
|
||||
const char *GetName() { return m_name.c_str(); }
|
||||
|
||||
uint32_t StartListeningForEventSpec(lldb::BroadcasterManagerSP manager_sp,
|
||||
const BroadcastEventSpec &event_spec);
|
||||
uint32_t
|
||||
StartListeningForEventSpec(const lldb::BroadcasterManagerSP &manager_sp,
|
||||
const BroadcastEventSpec &event_spec);
|
||||
|
||||
bool StopListeningForEventSpec(lldb::BroadcasterManagerSP manager_sp,
|
||||
bool StopListeningForEventSpec(const lldb::BroadcasterManagerSP &manager_sp,
|
||||
const BroadcastEventSpec &event_spec);
|
||||
|
||||
uint32_t StartListeningForEvents(Broadcaster *broadcaster,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
|
@ -27,7 +28,7 @@ using namespace lldb_private;
|
|||
|
||||
Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name)
|
||||
: m_broadcaster_sp(std::make_shared<BroadcasterImpl>(*this)),
|
||||
m_manager_sp(manager_sp), m_broadcaster_name(name) {
|
||||
m_manager_sp(std::move(manager_sp)), m_broadcaster_name(name) {
|
||||
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
|
||||
if (log)
|
||||
log->Printf("%p Broadcaster::Broadcaster(\"%s\")",
|
||||
|
@ -334,7 +335,7 @@ lldb::BroadcasterManagerSP BroadcasterManager::MakeBroadcasterManager() {
|
|||
}
|
||||
|
||||
uint32_t BroadcasterManager::RegisterListenerForEvents(
|
||||
const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec) {
|
||||
const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec) {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
|
||||
|
||||
collection::iterator iter = m_event_map.begin(), end_iter = m_event_map.end();
|
||||
|
@ -359,7 +360,7 @@ uint32_t BroadcasterManager::RegisterListenerForEvents(
|
|||
}
|
||||
|
||||
bool BroadcasterManager::UnregisterListenerForEvents(
|
||||
const lldb::ListenerSP &listener_sp, BroadcastEventSpec event_spec) {
|
||||
const lldb::ListenerSP &listener_sp, const BroadcastEventSpec &event_spec) {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
|
||||
bool removed_some = false;
|
||||
|
||||
|
@ -399,7 +400,7 @@ bool BroadcasterManager::UnregisterListenerForEvents(
|
|||
}
|
||||
|
||||
ListenerSP BroadcasterManager::GetListenerForEventSpec(
|
||||
BroadcastEventSpec event_spec) const {
|
||||
const BroadcastEventSpec &event_spec) const {
|
||||
std::lock_guard<std::recursive_mutex> guard(m_manager_mutex);
|
||||
|
||||
collection::const_iterator iter, end_iter = m_event_map.end();
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace {
|
|||
class BroadcasterManagerWPMatcher {
|
||||
public:
|
||||
BroadcasterManagerWPMatcher(BroadcasterManagerSP manager_sp)
|
||||
: m_manager_sp(manager_sp) {}
|
||||
bool operator()(const BroadcasterManagerWP input_wp) const {
|
||||
: m_manager_sp(std::move(manager_sp)) {}
|
||||
bool operator()(const BroadcasterManagerWP &input_wp) const {
|
||||
BroadcasterManagerSP input_sp = input_wp.lock();
|
||||
return (input_sp && input_sp == m_manager_sp);
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ void Listener::BroadcasterManagerWillDestruct(BroadcasterManagerSP manager_sp) {
|
|||
end_iter = m_broadcaster_managers.end();
|
||||
BroadcasterManagerWP manager_wp;
|
||||
|
||||
BroadcasterManagerWPMatcher matcher(manager_sp);
|
||||
BroadcasterManagerWPMatcher matcher(std::move(manager_sp));
|
||||
iter = std::find_if<broadcaster_manager_collection::iterator,
|
||||
BroadcasterManagerWPMatcher>(
|
||||
m_broadcaster_managers.begin(), end_iter, matcher);
|
||||
|
@ -424,7 +424,7 @@ size_t Listener::HandleBroadcastEvent(EventSP &event_sp) {
|
|||
}
|
||||
|
||||
uint32_t
|
||||
Listener::StartListeningForEventSpec(BroadcasterManagerSP manager_sp,
|
||||
Listener::StartListeningForEventSpec(const BroadcasterManagerSP &manager_sp,
|
||||
const BroadcastEventSpec &event_spec) {
|
||||
if (!manager_sp)
|
||||
return 0;
|
||||
|
@ -452,7 +452,7 @@ Listener::StartListeningForEventSpec(BroadcasterManagerSP manager_sp,
|
|||
return bits_acquired;
|
||||
}
|
||||
|
||||
bool Listener::StopListeningForEventSpec(BroadcasterManagerSP manager_sp,
|
||||
bool Listener::StopListeningForEventSpec(const BroadcasterManagerSP &manager_sp,
|
||||
const BroadcastEventSpec &event_spec) {
|
||||
if (!manager_sp)
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue