aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-05-03 12:44:49 +0100
committerJon Leighton <j@jonathanleighton.com>2013-05-03 12:45:02 +0100
commit30f297bef5fec202ee6b26e67c9e45fb7a500251 (patch)
tree8f99638d866251549f89ed4acfc0bb17d0c51dc7 /activesupport/lib
parentffaceaa8cf1381acbf1becf0f50cade88eafdc4c (diff)
downloadrails-30f297bef5fec202ee6b26e67c9e45fb7a500251.tar.gz
rails-30f297bef5fec202ee6b26e67c9e45fb7a500251.tar.bz2
rails-30f297bef5fec202ee6b26e67c9e45fb7a500251.zip
Revert "Merge pull request #10433 from wangjohn/making_callbacks_more_performant"
This reverts commit 09751fdc847c25237891a8fcb0c2312e39bbe86d, reversing changes made to 6a5ab08d21c4284a05f5e34484b18a91d4e5c50c. This change caused a failure in actionpack/test/abstract/callbacks_test.rb.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/callbacks.rb44
1 files changed, 11 insertions, 33 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index f0389d0a1c..893c2500d7 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -132,10 +132,6 @@ module ActiveSupport
@@_callback_sequence += 1
end
- def object_filter?
- @_is_object_filter
- end
-
def matches?(_kind, _filter)
if @_is_object_filter
_filter_matches = @filter.to_s.start_with?(_method_name_for_object_filter(_kind, _filter, false))
@@ -341,7 +337,6 @@ module ActiveSupport
:terminator => "false",
:scope => [ :kind ]
}.merge!(config)
- @callbacks_hash = Hash.new { |h, k| h[k] = [] }
end
def compile
@@ -366,37 +361,20 @@ module ActiveSupport
private
- def append_one(callback)
- handle_duplicates(callback)
- push(callback)
- end
+ def append_one(callback)
+ remove_duplicates(callback)
+ push(callback)
+ end
- def prepend_one(callback)
- handle_duplicates(callback)
- unshift(callback)
- end
+ def prepend_one(callback)
+ remove_duplicates(callback)
+ unshift(callback)
+ end
- # We check to see if this callback already exists. If it does (i.e. if
- # +callback.duplicates?(c)+ for any callback +c+ in the list of
- # callbacks), then we delete the previously defined callback.
- #
- # We make use of the rep-invariant that only one callback exists which
- # might match the new callback. The +@callbacks_hash+ is keyed on the
- # +kind+ and +filter+ of the callback, the attributes used to check if
- # two callbacks match.
- def handle_duplicates(callback)
- if callback.object_filter?
- scan_and_remove_duplicates(callback)
- else
- hash_key = [callback.kind, callback.filter]
- delete @callbacks_hash[hash_key] if @callbacks_hash[hash_key]
- @callbacks_hash[hash_key] = callback
- end
- end
+ def remove_duplicates(callback)
+ delete_if { |c| callback.duplicates?(c) }
+ end
- def scan_and_remove_duplicates(callback)
- delete_if { |c| callback.duplicates?(c) }
- end
end
module ClassMethods