diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-16 15:36:55 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-16 15:36:55 -0800 |
commit | ccfa01c36e79013881ffdb7ebe397cec733d15b2 (patch) | |
tree | 808756b0ac5c093d4653b3014c1b32e4a2ebd99d | |
parent | a08827a90b5a9be79379019cf5b242bd7236d2e3 (diff) | |
download | rails-ccfa01c36e79013881ffdb7ebe397cec733d15b2.tar.gz rails-ccfa01c36e79013881ffdb7ebe397cec733d15b2.tar.bz2 rails-ccfa01c36e79013881ffdb7ebe397cec733d15b2.zip |
Pull output buffer conditional up
This pulls the "output buffer existence" conditional up. Instead of
evaling the same conditional over and over, we can pull it in to "only
compiled once" Ruby code.
-rw-r--r-- | actionview/lib/action_view/template.rb | 2 | ||||
-rw-r--r-- | actionview/lib/action_view/template/handlers/erb/erubi.rb | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 070d82cf17..da9f20990f 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -155,7 +155,7 @@ module ActionView # This method is instrumented as "!render_template.action_view". Notice that # we use a bang in this instrumentation because you don't want to # consume this in production. This is only slow if it's being listened to. - def render(view, locals, buffer = nil, &block) + def render(view, locals, buffer = ActionView::OutputBuffer.new, &block) instrument_render_template do compile!(view) view.send(method_name, locals, buffer, &block) diff --git a/actionview/lib/action_view/template/handlers/erb/erubi.rb b/actionview/lib/action_view/template/handlers/erb/erubi.rb index db75f028ed..d379d7ec12 100644 --- a/actionview/lib/action_view/template/handlers/erb/erubi.rb +++ b/actionview/lib/action_view/template/handlers/erb/erubi.rb @@ -13,7 +13,7 @@ module ActionView # Dup properties so that we don't modify argument properties = Hash[properties] - properties[:preamble] = "@output_buffer = output_buffer || ActionView::OutputBuffer.new;" + properties[:preamble] = "@output_buffer = output_buffer;" properties[:postamble] = "@output_buffer.to_s" properties[:bufvar] = "@output_buffer" properties[:escapefunc] = "" @@ -23,6 +23,8 @@ module ActionView def evaluate(action_view_erb_handler_context) pr = eval("proc { #{@src} }", binding, @filename || "(erubi)") + # Double assignment to eliminate -w warnings + output_buffer = output_buffer = ActionView::OutputBuffer.new action_view_erb_handler_context.instance_eval(&pr) end |