diff options
author | Guo Xiang Tan <tgx_world@hotmail.com> | 2014-06-01 13:45:27 -0700 |
---|---|---|
committer | Guo Xiang Tan <tgx_world@hotmail.com> | 2014-06-01 14:56:30 -0700 |
commit | a8439bc470e90cce44fef6c182d94cf01a944f1e (patch) | |
tree | 720a4e1312eae9e71d141a9cfbbfa54437c3948f /activesupport | |
parent | a67fdc0256a88eeabd6cef6743bb480c9889642f (diff) | |
download | rails-a8439bc470e90cce44fef6c182d94cf01a944f1e.tar.gz rails-a8439bc470e90cce44fef6c182d94cf01a944f1e.tar.bz2 rails-a8439bc470e90cce44fef6c182d94cf01a944f1e.zip |
Avoid looping through subscribers when unsubscribing with a subscriber object.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 5f0bc3dca0..6bf8c7d5de 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -27,7 +27,13 @@ module ActiveSupport def unsubscribe(subscriber_or_name) synchronize do - @subscribers.reject! { |s| s.matches?(subscriber_or_name) } + case subscriber_or_name + when String + @subscribers.reject! { |s| s.matches?(subscriber_or_name) } + else + @subscribers.delete(subscriber_or_name) + end + @listeners_for.clear end end @@ -97,12 +103,11 @@ module ActiveSupport end def subscribed_to?(name) - @pattern === name.to_s + @pattern === name end - def matches?(subscriber_or_name) - self === subscriber_or_name || - @pattern && @pattern === subscriber_or_name + def matches?(name) + @pattern && @pattern === name end end |