1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

AS::Callbacks optimized to reduce call backtrace

This commit is contained in:
Bogdan Gusiev 2012-04-27 10:12:47 +03:00
parent 363a06f351
commit 764f69e841

View file

@ -76,7 +76,8 @@ module ActiveSupport
# #
def run_callbacks(kind, key = nil, &block) def run_callbacks(kind, key = nil, &block)
#TODO: deprecate key argument #TODO: deprecate key argument
self.class.__run_callbacks(kind, self, &block) runner_name = self.class.__define_callbacks(kind, self)
send(runner_name, &block)
end end
private private
@ -323,18 +324,17 @@ module ActiveSupport
method << callbacks method << callbacks
method << "halted ? false : (block_given? ? value : true)" method << "halted ? false : (block_given? ? value : true)"
method.flatten.compact.join("\n") method.join("\n")
end end
end end
module ClassMethods module ClassMethods
# This method runs callback chain for the given kind. # This method defines callback chain method for the given kind
# If this called first time it creates a new callback method for the kind. # if it was not yet defined.
# This generated method plays caching role. # This generated method plays caching role.
# def __define_callbacks(kind, object) #:nodoc:
def __run_callbacks(kind, object, &blk) #:nodoc:
name = __callback_runner_name(kind) name = __callback_runner_name(kind)
unless object.respond_to?(name, true) unless object.respond_to?(name, true)
str = object.send("_#{kind}_callbacks").compile str = object.send("_#{kind}_callbacks").compile
@ -343,7 +343,7 @@ module ActiveSupport
protected :#{name} protected :#{name}
RUBY_EVAL RUBY_EVAL
end end
object.send(name, &blk) name
end end
def __reset_runner(symbol) def __reset_runner(symbol)