aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-09-29 12:34:53 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-09-29 12:34:53 -0700
commita455e3f4e9dbfb9630d47878e1239bc424fb7d13 (patch)
tree2b1f86d41899babb0856e56b1f767a289b7cd39b /activesupport
parent035cc69c48d9d538bded70fc88976cd7f23966f5 (diff)
parent796cab45561fce268aa74e6587cdb9cae3bb243e (diff)
downloadrails-a455e3f4e9dbfb9630d47878e1239bc424fb7d13.tar.gz
rails-a455e3f4e9dbfb9630d47878e1239bc424fb7d13.tar.bz2
rails-a455e3f4e9dbfb9630d47878e1239bc424fb7d13.zip
Merge pull request #17093 from phiggins/remove-dynamic-send-on-built-in-callbacks
Reduce allocations when running AR callbacks.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb21
1 files changed, 15 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index cd467e13f6..0c8c1d7dfb 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -78,18 +78,21 @@ module ActiveSupport
# save
# end
def run_callbacks(kind, &block)
- cbs = send("_#{kind}_callbacks")
- if cbs.empty?
- yield if block_given?
+ send "run_#{kind}_callbacks", &block
+ end
+
+ private
+
+ def _run_callbacks(callbacks, &block)
+ if callbacks.empty?
+ block.call if block
else
- runner = cbs.compile
+ runner = callbacks.compile
e = Filters::Environment.new(self, false, nil, block)
runner.call(e).value
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.
@@ -722,6 +725,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