From a4c15303cbc96fffd66c68abdeebe73d8883e5ab Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 18 Apr 2008 14:44:55 -0500 Subject: Slight optimization to CallbackChain#union and delete. --- activesupport/lib/active_support/callbacks.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 282b6cbcbc..5c51237049 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -97,15 +97,14 @@ module ActiveSupport end def |(chain) - if chain.is_a?(Callback) - if found_callback = find(chain) - index = index(found_callback) + if chain.is_a?(CallbackChain) + chain.each { |callback| self | callback } + elsif chain.is_a?(Callback) + if index = index(chain) self[index] = chain else self << chain end - else - chain.each { |callback| self | callback } end self end @@ -115,7 +114,7 @@ module ActiveSupport end def delete(callback) - super(find(callback)) + super(callback.is_a?(Callback) ? callback : find(callback)) end private -- cgit v1.2.3