diff options
author | Jeremy Kemper <jeremykemper@gmail.com> | 2014-09-27 20:03:35 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremykemper@gmail.com> | 2014-09-27 20:03:35 -0700 |
commit | e1e8e532ac30d69148fc6ffb71b826a1d130588b (patch) | |
tree | c130a2f0fa6ac39c14e0795b93ef88e57b9aac12 /railties/lib | |
parent | d63005447b143e3308c9e8e430216cd7bb144c6c (diff) | |
parent | dfbcfafd9af046b3e8c79fe7309d31af6f82f9b2 (diff) | |
download | rails-e1e8e532ac30d69148fc6ffb71b826a1d130588b.tar.gz rails-e1e8e532ac30d69148fc6ffb71b826a1d130588b.tar.bz2 rails-e1e8e532ac30d69148fc6ffb71b826a1d130588b.zip |
Merge pull request #17077 from schneems/schneems/backtrace-string-allocations
Decrease backtrace cleaner object allocations
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/backtrace_cleaner.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 8cc8eb1103..5276eb33c9 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -4,12 +4,16 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner APP_DIRS_PATTERN = /^\/?(app|config|lib|test)/ RENDER_TEMPLATE_PATTERN = /:in `_render_template_\w*'/ + EMPTY_STRING = ''.freeze + SLASH = '/'.freeze + DOT_SLASH = './'.freeze def initialize super - add_filter { |line| line.sub("#{Rails.root}/", '') } - add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, '') } - add_filter { |line| line.sub('./', '/') } # for tests + @root = "#{Rails.root}/".freeze + add_filter { |line| line.sub(@root, EMPTY_STRING) } + add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, EMPTY_STRING) } + add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests add_gem_filters add_silencer { |line| line !~ APP_DIRS_PATTERN } @@ -21,7 +25,8 @@ module Rails return if gems_paths.empty? gems_regexp = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)} - add_filter { |line| line.sub(gems_regexp, '\2 (\3) \4') } + gems_result = '\2 (\3) \4'.freeze + add_filter { |line| line.sub(gems_regexp, gems_result) } end end end |