Skip to content

Commit

Permalink
Pull output buffer conditional up
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tenderlove committed Jan 16, 2019
1 parent a08827a commit ccfa01c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion actionview/lib/action_view/template.rb
Expand Up @@ -155,7 +155,7 @@ def supports_streaming?
# 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)
Expand Down
4 changes: 3 additions & 1 deletion actionview/lib/action_view/template/handlers/erb/erubi.rb
Expand Up @@ -13,7 +13,7 @@ def initialize(input, properties = {})

# 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] = ""
Expand All @@ -23,6 +23,8 @@ def initialize(input, properties = {})

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

Expand Down

0 comments on commit ccfa01c

Please sign in to comment.