mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 09:20:42 -07:00
Replace @blocks.each with while loop in If render — avoids block proc allocation per render\n\nResult: {"status":"keep","combined_µs":3496,"parse_µs":2356,"render_µs":1140,"allocations":24530}
This commit is contained in:
@@ -51,14 +51,17 @@ module Liquid
|
||||
end
|
||||
|
||||
def render_to_output_buffer(context, output)
|
||||
@blocks.each do |block|
|
||||
idx = 0
|
||||
blocks = @blocks
|
||||
while idx < blocks.length
|
||||
block = blocks[idx]
|
||||
result = block.evaluate(context)
|
||||
# Inline to_liquid_value fast path — respond_to? check is rarely true
|
||||
result = result.to_liquid_value if result.respond_to?(:to_liquid_value)
|
||||
|
||||
if result
|
||||
return block.attachment.render_to_output_buffer(context, output)
|
||||
end
|
||||
idx += 1
|
||||
end
|
||||
|
||||
output
|
||||
|
||||
Reference in New Issue
Block a user