Skip to content

Commit

Permalink
EventEmitter and detail::event_emitter classes take callback object a…
Browse files Browse the repository at this point in the history
…s const reference instead of 'value copy'
  • Loading branch information
d5 committed Feb 22, 2012
1 parent 04fd5a2 commit 5079214
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions native/detail/base.h
Expand Up @@ -248,7 +248,7 @@ namespace native

public:
template<typename T>
void* add(T callback, bool once=false)
void* add(const T& callback, bool once=false)
{
if(!callbacks_)
{
Expand All @@ -265,7 +265,7 @@ namespace native
}

template<typename T>
static void add(void* target, T callback, bool once=false)
static void add(void* target, const T& callback, bool once=false)
{
auto self = reinterpret_cast<event_emitter*>(target);
assert(self);
Expand Down
6 changes: 3 additions & 3 deletions native/events.h
Expand Up @@ -217,7 +217,7 @@ namespace native
* If EventEmitter fails to add the listener, it returns nullptr.
*/
template<typename E>
listener_t addListener(typename E::callback_type callback)
listener_t addListener(const typename E::callback_type& callback)
{
auto s = events_.find(typeid(E).hash_code());
if(s != events_.end())
Expand All @@ -238,7 +238,7 @@ namespace native
* If EventEmitter fails to add the listener, it returns nullptr.
*/
template<typename E>
listener_t on(typename E::callback_type callback)
listener_t on(const typename E::callback_type& callback)
{
return addListener<E>(callback);
}
Expand All @@ -253,7 +253,7 @@ namespace native
* If EventEmitter fails to add the listener, it returns nullptr.
*/
template<typename E>
listener_t once(typename E::callback_type callback)
listener_t once(const typename E::callback_type& callback)
{
auto s = events_.find(typeid(E).hash_code());
if(s != events_.end())
Expand Down

0 comments on commit 5079214

Please sign in to comment.