aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorBogdan Gusiev <agresso@gmail.com>2011-12-25 16:44:19 +0200
committerSergey Nartimov <just.lest@gmail.com>2012-01-03 22:14:27 +0300
commit9f8f4c28718d5688f18140111eac517a5ef8142e (patch)
tree5f06f6564027c357c0feaae1ab3ac4c136aa7acf /activesupport
parenteafdf6c9bd22706941456a6bacb9f2fff8d14104 (diff)
downloadrails-9f8f4c28718d5688f18140111eac517a5ef8142e.tar.gz
rails-9f8f4c28718d5688f18140111eac517a5ef8142e.tar.bz2
rails-9f8f4c28718d5688f18140111eac517a5ef8142e.zip
AS::Callbacks: improve __define_runner perfomance
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb21
1 files changed, 11 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 11069301f1..ba9fb4ecce 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -378,18 +378,15 @@ module ActiveSupport
module ClassMethods
# Generate the internal runner method called by +run_callbacks+.
def __define_runner(symbol) #:nodoc:
- body = send("_#{symbol}_callbacks").compile
- runner_method = "_run_#{symbol}_callbacks"
+ name = __callback_runner_name(nil, symbol)
+ undef_method(name) if method_defined?(name)
silence_warnings do
+ runner_method = "_run_#{symbol}_callbacks"
undef_method runner_method if method_defined?(runner_method)
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{runner_method}(key = nil, &blk)
- if key
- self.class.__run_keyed_callback(key, :#{symbol}, self, &blk)
- else
- #{body}
- end
+ self.class.__run_callback(key, :#{symbol}, self, &blk)
end
private :#{runner_method}
RUBY_EVAL
@@ -400,10 +397,10 @@ module ActiveSupport
# If this called first time it creates a new callback method for the key,
# calculating which callbacks can be omitted because of per_key conditions.
#
- def __run_keyed_callback(key, kind, object, &blk) #:nodoc:
- name = "_run__#{self.name.hash.abs}__#{kind}__#{key.hash.abs}__callbacks"
+ def __run_callback(key, kind, object, &blk) #:nodoc:
+ name = __callback_runner_name(key, kind)
unless object.respond_to?(name)
- str = send("_#{kind}_callbacks").compile(name, object)
+ str = send("_#{kind}_callbacks").compile(key, object)
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{name}() #{str} end
protected :#{name}
@@ -412,6 +409,10 @@ module ActiveSupport
object.send(name, &blk)
end
+ def __callback_runner_name(key, kind)
+ "_run__#{self.name.hash.abs}__#{kind}__#{key.hash.abs}__callbacks"
+ end
+
# This is used internally to append, prepend and skip callbacks to the
# CallbackChain.
#