mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
lazily create stacks
This commit is contained in:
@@ -41,6 +41,7 @@ module Liquid
|
|||||||
|
|
||||||
singleton_class.send(:attr_accessor, :cache_classes)
|
singleton_class.send(:attr_accessor, :cache_classes)
|
||||||
self.cache_classes = true
|
self.cache_classes = true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require "liquid/version"
|
require "liquid/version"
|
||||||
|
|||||||
+15
-2
@@ -27,6 +27,12 @@ module Liquid
|
|||||||
@parsed_variables = Hash.new{ |cache, markup| cache[markup] = variable_parse(markup) }
|
@parsed_variables = Hash.new{ |cache, markup| cache[markup] = variable_parse(markup) }
|
||||||
squash_instance_assigns_with_environments
|
squash_instance_assigns_with_environments
|
||||||
|
|
||||||
|
@used_stacks = 0
|
||||||
|
@unused_stacks = 0
|
||||||
|
@max_stack_depth = 0
|
||||||
|
@this_stack_depth = 0
|
||||||
|
@this_stack_used = false
|
||||||
|
|
||||||
if rethrow_errors
|
if rethrow_errors
|
||||||
self.exception_handler = ->(e) { true }
|
self.exception_handler = ->(e) { true }
|
||||||
end
|
end
|
||||||
@@ -134,10 +140,13 @@ module Liquid
|
|||||||
#
|
#
|
||||||
# context['var] #=> nil
|
# context['var] #=> nil
|
||||||
def stack(new_scope={})
|
def stack(new_scope={})
|
||||||
push(new_scope)
|
old_stack_used = @this_stack_used
|
||||||
|
@this_stack_used = (new_scope != {})
|
||||||
|
push(new_scope) if @this_stack_used
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
pop
|
pop if @this_stack_used
|
||||||
|
@this_stack_used = old_stack_used
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_instance_assigns
|
def clear_instance_assigns
|
||||||
@@ -146,6 +155,10 @@ 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)
|
||||||
|
if !@this_stack_used
|
||||||
|
@this_stack_used = true
|
||||||
|
push({})
|
||||||
|
end
|
||||||
@scopes[0][key] = value
|
@scopes[0][key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user