Skip to content

Commit a89827e

Browse files
committed
Merge pull request rails#5999 from bogdan/callbacks
AS::Callbacks#run_callbacks optimized to reduce backtrace
2 parents 3de6a75 + 764f69e commit a89827e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

activesupport/lib/active_support/callbacks.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ module Callbacks
7676
#
7777
def run_callbacks(kind, key = nil, &block)
7878
#TODO: deprecate key argument
79-
self.class.__run_callbacks(kind, self, &block)
79+
runner_name = self.class.__define_callbacks(kind, self)
80+
send(runner_name, &block)
8081
end
8182

8283
private
@@ -323,18 +324,17 @@ def compile
323324
method << callbacks
324325

325326
method << "halted ? false : (block_given? ? value : true)"
326-
method.flatten.compact.join("\n")
327+
method.join("\n")
327328
end
328329

329330
end
330331

331332
module ClassMethods
332333

333-
# This method runs callback chain for the given kind.
334-
# If this called first time it creates a new callback method for the kind.
334+
# This method defines callback chain method for the given kind
335+
# if it was not yet defined.
335336
# This generated method plays caching role.
336-
#
337-
def __run_callbacks(kind, object, &blk) #:nodoc:
337+
def __define_callbacks(kind, object) #:nodoc:
338338
name = __callback_runner_name(kind)
339339
unless object.respond_to?(name, true)
340340
str = object.send("_#{kind}_callbacks").compile
@@ -343,7 +343,7 @@ def #{name}() #{str} end
343343
protected :#{name}
344344
RUBY_EVAL
345345
end
346-
object.send(name, &blk)
346+
name
347347
end
348348

349349
def __reset_runner(symbol)

0 commit comments

Comments
 (0)