mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert "Merge pull request #10433 from wangjohn/making_callbacks_more_performant"
This reverts commit09751fdc84
, reversing changes made to6a5ab08d21
. This change caused a failure in actionpack/test/abstract/callbacks_test.rb.
This commit is contained in:
parent
ffaceaa8cf
commit
30f297bef5
1 changed files with 11 additions and 33 deletions
|
@ -132,10 +132,6 @@ module ActiveSupport
|
||||||
@@_callback_sequence += 1
|
@@_callback_sequence += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_filter?
|
|
||||||
@_is_object_filter
|
|
||||||
end
|
|
||||||
|
|
||||||
def matches?(_kind, _filter)
|
def matches?(_kind, _filter)
|
||||||
if @_is_object_filter
|
if @_is_object_filter
|
||||||
_filter_matches = @filter.to_s.start_with?(_method_name_for_object_filter(_kind, _filter, false))
|
_filter_matches = @filter.to_s.start_with?(_method_name_for_object_filter(_kind, _filter, false))
|
||||||
|
@ -341,7 +337,6 @@ module ActiveSupport
|
||||||
:terminator => "false",
|
:terminator => "false",
|
||||||
:scope => [ :kind ]
|
:scope => [ :kind ]
|
||||||
}.merge!(config)
|
}.merge!(config)
|
||||||
@callbacks_hash = Hash.new { |h, k| h[k] = [] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile
|
def compile
|
||||||
|
@ -366,37 +361,20 @@ module ActiveSupport
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def append_one(callback)
|
def append_one(callback)
|
||||||
handle_duplicates(callback)
|
remove_duplicates(callback)
|
||||||
push(callback)
|
push(callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepend_one(callback)
|
def prepend_one(callback)
|
||||||
handle_duplicates(callback)
|
remove_duplicates(callback)
|
||||||
unshift(callback)
|
unshift(callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
# We check to see if this callback already exists. If it does (i.e. if
|
def remove_duplicates(callback)
|
||||||
# +callback.duplicates?(c)+ for any callback +c+ in the list of
|
delete_if { |c| callback.duplicates?(c) }
|
||||||
# callbacks), then we delete the previously defined callback.
|
end
|
||||||
#
|
|
||||||
# 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 scan_and_remove_duplicates(callback)
|
|
||||||
delete_if { |c| callback.duplicates?(c) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
Loading…
Reference in a new issue