From 68b7e381f1c9a0ee9689ea56f14ae2a3ac8fd182 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 6 Nov 2013 14:37:30 -0800 Subject: drop string allocations in the log subscriber --- actionview/lib/action_view/log_subscriber.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/actionview/lib/action_view/log_subscriber.rb b/actionview/lib/action_view/log_subscriber.rb index 354a136894..9336b29d0b 100644 --- a/actionview/lib/action_view/log_subscriber.rb +++ b/actionview/lib/action_view/log_subscriber.rb @@ -5,7 +5,12 @@ module ActionView # # Provides functionality so that Rails can output logs from Action View. class LogSubscriber < ActiveSupport::LogSubscriber - VIEWS_PATTERN = /^app\/views\//.freeze + VIEWS_PATTERN = /^app\/views\// + + def initialize + @root = nil + super + end def render_template(event) return unless logger.info? @@ -23,8 +28,13 @@ module ActionView protected + EMPTY = '' def from_rails_root(string) - string.sub("#{Rails.root}/", "").sub(VIEWS_PATTERN, "") + string.sub(rails_root, EMPTY).sub(VIEWS_PATTERN, EMPTY) + end + + def rails_root + @root ||= "#{Rails.root}/" end end end -- cgit v1.2.3