aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-15 14:26:09 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-07-15 14:26:09 -0300
commit64c1264419f766a306eba0418c1030b87489ea67 (patch)
tree1aee52a2e2434d2e7eecc67f94683e99823e79d0 /activesupport
parenta0b4dc21a2188a4379bc401b73336608fec56c64 (diff)
parentbeb07fbfae845d20323a9863c7216c6b63aff9c7 (diff)
downloadrails-64c1264419f766a306eba0418c1030b87489ea67.tar.gz
rails-64c1264419f766a306eba0418c1030b87489ea67.tar.bz2
rails-64c1264419f766a306eba0418c1030b87489ea67.zip
Merge pull request #20887 from tgxworld/ar_callbacks
Revert "Revert "Reduce allocations when running AR callbacks.""
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index e8ab3a7db5..f35e1f5098 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -80,8 +80,12 @@ module ActiveSupport
# save
# end
def run_callbacks(kind, &block)
- callbacks = send("_#{kind}_callbacks")
+ send "_run_#{kind}_callbacks", &block
+ end
+
+ private
+ def __run_callbacks__(callbacks, &block)
if callbacks.empty?
yield if block_given?
else
@@ -91,8 +95,6 @@ module ActiveSupport
end
end
- private
-
# A hook invoked every time a before callback is halted.
# This can be overridden in AS::Callback implementors in order
# to provide better debugging/logging.
@@ -806,6 +808,12 @@ module ActiveSupport
names.each do |name|
class_attribute "_#{name}_callbacks"
set_callbacks name, CallbackChain.new(name, options)
+
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def _run_#{name}_callbacks(&block)
+ __run_callbacks__(_#{name}_callbacks, &block)
+ end
+ RUBY
end
end