Skip to content

Commit 5374960

Browse files
amatsudaarunagw
authored andcommitted
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
1 parent ad6adcb commit 5374960

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

railties/lib/rails/engine.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,13 @@ def inherited(base)
351351
Rails::Railtie::Configuration.eager_load_namespaces << base
352352

353353
base.called_from = begin
354-
# Remove the line number from backtraces making sure we don't leave anything behind
355-
call_stack = caller.map { |p| p.sub(/:\d+.*/, '') }
354+
call_stack = if Kernel.respond_to?(:caller_locations)
355+
caller_locations.map(&:path)
356+
else
357+
# Remove the line number from backtraces making sure we don't leave anything behind
358+
caller.map { |p| p.sub(/:\d+.*/, '') }
359+
end
360+
356361
File.dirname(call_stack.detect { |p| p !~ %r[railties[\w.-]*/lib/rails|rack[\w.-]*/lib/rack] })
357362
end
358363
end

0 commit comments

Comments
 (0)