aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/render/rendering.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-19 17:20:15 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-19 17:20:20 +0100
commitf28d856cece877d1b2f306f54aeb12cce1db1023 (patch)
treef2ca547068d20558acc80433ef5f667f61f78737 /actionpack/lib/action_view/render/rendering.rb
parentfbe35656a95228f760a2cd09676423ba41fe70ab (diff)
downloadrails-f28d856cece877d1b2f306f54aeb12cce1db1023.tar.gz
rails-f28d856cece877d1b2f306f54aeb12cce1db1023.tar.bz2
rails-f28d856cece877d1b2f306f54aeb12cce1db1023.zip
Improve performance of the rendering stack by freezing formats as a sign that they shouldn't be further modified.
Diffstat (limited to 'actionpack/lib/action_view/render/rendering.rb')
-rw-r--r--actionpack/lib/action_view/render/rendering.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb
index b0fed556c3..a8f745afd1 100644
--- a/actionpack/lib/action_view/render/rendering.rb
+++ b/actionpack/lib/action_view/render/rendering.rb
@@ -21,7 +21,7 @@ module ActionView
_render_partial(options)
else
template = _determine_template(options)
- self.formats = template.formats
+ _freeze_formats(template.formats)
_render_template(template, options[:layout], options)
end
when :update
@@ -58,12 +58,18 @@ module ActionView
content = template.render(self, locals) { |*name| _layout_for(*name) }
@_content_for[:layout] = content
- if layout
- content = _render_layout(layout, locals)
- end
-
+ content = _render_layout(layout, locals) if layout
content
end
end
+
+ # Freeze the current formats in the lookup context. By freezing them, you are guaranteeing
+ # that next template lookups are not going to modify the formats. The controller can also
+ # use this, to ensure that formats won't be further modified (as it does in respond_to blocks).
+ def _freeze_formats(formats) #:nodoc:
+ return if self.formats.frozen?
+ self.formats = formats
+ self.formats.freeze
+ end
end
end