From ccfa01c36e79013881ffdb7ebe397cec733d15b2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 16 Jan 2019 15:36:55 -0800 Subject: 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. --- actionview/lib/action_view/template.rb | 2 +- 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 -- cgit v1.2.3