mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 02:40:41 -07:00
Remove lazy load stacks
Remove lazy load stacks and instead only create a new scope when a tag is known to need one
This commit is contained in:
+18
-17
@@ -25,8 +25,6 @@ module Liquid
|
||||
@resource_limits = resource_limits || ResourceLimits.new(Template.default_resource_limits)
|
||||
squash_instance_assigns_with_environments
|
||||
|
||||
@this_stack_used = false
|
||||
|
||||
self.exception_renderer = Template.default_exception_renderer
|
||||
if rethrow_errors
|
||||
self.exception_renderer = ->(e) { raise }
|
||||
@@ -111,19 +109,26 @@ module Liquid
|
||||
# end
|
||||
#
|
||||
# context['var] #=> nil
|
||||
def stack(new_scope = nil)
|
||||
old_stack_used = @this_stack_used
|
||||
if new_scope
|
||||
push(new_scope)
|
||||
@this_stack_used = true
|
||||
else
|
||||
@this_stack_used = false
|
||||
end
|
||||
|
||||
#
|
||||
# false or {} can be used to control if a new scope is needed
|
||||
#
|
||||
# Example:
|
||||
# new_scope = false
|
||||
# context.stack(new_scope) do
|
||||
# # no scope created
|
||||
# end
|
||||
#
|
||||
# Example:
|
||||
# new_scope = {}
|
||||
# context.stack(new_scope) do
|
||||
# # scope created
|
||||
# end
|
||||
#
|
||||
def stack(new_scope = {})
|
||||
push(new_scope) unless new_scope == false
|
||||
yield
|
||||
ensure
|
||||
pop if @this_stack_used
|
||||
@this_stack_used = old_stack_used
|
||||
pop unless new_scope == false
|
||||
end
|
||||
|
||||
def clear_instance_assigns
|
||||
@@ -132,10 +137,6 @@ module Liquid
|
||||
|
||||
# Only allow String, Numeric, Hash, Array, Proc, Boolean or <tt>Liquid::Drop</tt>
|
||||
def []=(key, value)
|
||||
unless @this_stack_used
|
||||
@this_stack_used = true
|
||||
push({})
|
||||
end
|
||||
@scopes[0][key] = value
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user