Browse files

drop string allocations in the log subscriber

  • Loading branch information...
1 parent 267e5c8 commit 68b7e381f1c9a0ee9689ea56f14ae2a3ac8fd182 @tenderlove tenderlove committed Nov 6, 2013
Showing with 12 additions and 2 deletions.
  1. +12 −2 actionview/lib/action_view/log_subscriber.rb
View
14 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 @@ def logger
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

0 comments on commit 68b7e38

Please sign in to comment.