提交 e1e8e532 编写于 作者: J Jeremy Kemper

Merge pull request #17077 from schneems/schneems/backtrace-string-allocations

Decrease backtrace cleaner object allocations
......@@ -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 @@ def add_gem_filters
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册