Compare commits

...

2 Commits

Author SHA1 Message Date
Mike Angell
dafbb4ae90 Remove hasnling false scopes 2019-08-31 20:03:54 +10:00
Mike Angell
2324564743 Remove lazy load stacks
Remove lazy load stacks and instead only create a new scope when a tag is known to need one
2019-08-29 09:09:32 +10:00
6 changed files with 40 additions and 64 deletions

View File

@@ -25,8 +25,6 @@ module Liquid
@resource_limits = resource_limits || ResourceLimits.new(Template.default_resource_limits) @resource_limits = resource_limits || ResourceLimits.new(Template.default_resource_limits)
squash_instance_assigns_with_environments squash_instance_assigns_with_environments
@this_stack_used = false
self.exception_renderer = Template.default_exception_renderer self.exception_renderer = Template.default_exception_renderer
if rethrow_errors if rethrow_errors
self.exception_renderer = ->(e) { raise } self.exception_renderer = ->(e) { raise }
@@ -111,19 +109,11 @@ module Liquid
# end # end
# #
# context['var] #=> nil # context['var] #=> nil
def stack(new_scope = nil) def stack(new_scope = {})
old_stack_used = @this_stack_used
if new_scope
push(new_scope) push(new_scope)
@this_stack_used = true
else
@this_stack_used = false
end
yield yield
ensure ensure
pop if @this_stack_used pop
@this_stack_used = old_stack_used
end end
def clear_instance_assigns def clear_instance_assigns
@@ -132,10 +122,6 @@ module Liquid
# Only allow String, Numeric, Hash, Array, Proc, Boolean or <tt>Liquid::Drop</tt> # Only allow String, Numeric, Hash, Array, Proc, Boolean or <tt>Liquid::Drop</tt>
def []=(key, value) def []=(key, value)
unless @this_stack_used
@this_stack_used = true
push({})
end
@scopes[0][key] = value @scopes[0][key] = value
end end

View File

@@ -39,7 +39,6 @@ module Liquid
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.stack do
execute_else_block = true execute_else_block = true
@blocks.each do |block| @blocks.each do |block|
@@ -50,7 +49,6 @@ module Liquid
block.attachment.render_to_output_buffer(context, output) block.attachment.render_to_output_buffer(context, output)
end end
end end
end
output output
end end

View File

@@ -34,7 +34,6 @@ module Liquid
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.registers[:cycle] ||= {} context.registers[:cycle] ||= {}
context.stack do
key = context.evaluate(@name) key = context.evaluate(@name)
iteration = context.registers[:cycle][key].to_i iteration = context.registers[:cycle][key].to_i
@@ -51,7 +50,6 @@ module Liquid
iteration += 1 iteration += 1
iteration = 0 if iteration >= @variables.size iteration = 0 if iteration >= @variables.size
context.registers[:cycle][key] = iteration context.registers[:cycle][key] = iteration
end
output output
end end

View File

@@ -40,13 +40,11 @@ module Liquid
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.stack do
@blocks.each do |block| @blocks.each do |block|
if block.evaluate(context) if block.evaluate(context)
return block.attachment.render_to_output_buffer(context, output) return block.attachment.render_to_output_buffer(context, output)
end end
end end
end
output output
end end

View File

@@ -1,7 +1,6 @@
module Liquid module Liquid
class Ifchanged < Block class Ifchanged < Block
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.stack do
block_output = '' block_output = ''
super(context, block_output) super(context, block_output)
@@ -9,7 +8,6 @@ module Liquid
context.registers[:ifchanged] = block_output context.registers[:ifchanged] = block_output
output << block_output output << block_output
end end
end
output output
end end

View File

@@ -7,7 +7,6 @@ module Liquid
# #
class Unless < If class Unless < If
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.stack do
# First condition is interpreted backwards ( if not ) # First condition is interpreted backwards ( if not )
first_block = @blocks.first first_block = @blocks.first
unless first_block.evaluate(context) unless first_block.evaluate(context)
@@ -20,7 +19,6 @@ module Liquid
return block.attachment.render_to_output_buffer(context, output) return block.attachment.render_to_output_buffer(context, output)
end end
end end
end
output output
end end