提交 5374960a 编写于 作者: A Akira Matsuda 提交者: Arun Agrawal

Use Ruby 2.0 caller_locations instead of caller if available

* we no more have to manipulate the each caller strings by ourselves using caller_locations

* caller_locations runs slightly faster, and creates less objects than good old caller
Benchmark (loading an Engine 1000 times):
  caller: 262.89 ms
  caller_locations: 186.068 ms
上级 ad6adcb6
......@@ -351,8 +351,13 @@ def inherited(base)
Rails::Railtie::Configuration.eager_load_namespaces << base
base.called_from = begin
# Remove the line number from backtraces making sure we don't leave anything behind
call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
call_stack = if Kernel.respond_to?(:caller_locations)
caller_locations.map(&:path)
else
# Remove the line number from backtraces making sure we don't leave anything behind
caller.map { |p| p.sub(/:\d+.*/, '') }
end
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册