From 0e38f88b58f02e93d321c8970b61f042b52465da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Tue, 5 May 2015 23:02:08 -0400 Subject: [PATCH] Recycle the array buffer in BlockBody#render --- lib/liquid/block_body.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 371e0581..4e9487a8 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -68,7 +68,8 @@ module Liquid end def render(context) - output = [] + @output ||= [] + @output.clear context.resource_limits.render_score += @nodelist.length @nodelist.each do |token| @@ -87,16 +88,16 @@ module Liquid token_output = render_token(token, context) unless token.is_a?(Block) && token.blank? - output << token_output + @output << token_output end rescue MemoryError => e raise e rescue ::StandardError => e - output << context.handle_error(e, token) + @output << context.handle_error(e, token) end end - output.join + @output.join end private