Skip to content

Commit ccfa01c

Browse files
committed
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.
1 parent a08827a commit ccfa01c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

actionview/lib/action_view/template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def supports_streaming?
155155
# This method is instrumented as "!render_template.action_view". Notice that
156156
# we use a bang in this instrumentation because you don't want to
157157
# consume this in production. This is only slow if it's being listened to.
158-
def render(view, locals, buffer = nil, &block)
158+
def render(view, locals, buffer = ActionView::OutputBuffer.new, &block)
159159
instrument_render_template do
160160
compile!(view)
161161
view.send(method_name, locals, buffer, &block)

actionview/lib/action_view/template/handlers/erb/erubi.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(input, properties = {})
1313

1414
# Dup properties so that we don't modify argument
1515
properties = Hash[properties]
16-
properties[:preamble] = "@output_buffer = output_buffer || ActionView::OutputBuffer.new;"
16+
properties[:preamble] = "@output_buffer = output_buffer;"
1717
properties[:postamble] = "@output_buffer.to_s"
1818
properties[:bufvar] = "@output_buffer"
1919
properties[:escapefunc] = ""
@@ -23,6 +23,8 @@ def initialize(input, properties = {})
2323

2424
def evaluate(action_view_erb_handler_context)
2525
pr = eval("proc { #{@src} }", binding, @filename || "(erubi)")
26+
# Double assignment to eliminate -w warnings
27+
output_buffer = output_buffer = ActionView::OutputBuffer.new
2628
action_view_erb_handler_context.instance_eval(&pr)
2729
end
2830

0 commit comments

Comments
 (0)