mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
add parse_simple to skip simple_lookup? check when caller validates
This commit is contained in:
@@ -163,9 +163,9 @@ module Liquid
|
|||||||
elsif Expression::LITERALS.key?(expr_markup)
|
elsif Expression::LITERALS.key?(expr_markup)
|
||||||
@name = Expression::LITERALS[expr_markup]
|
@name = Expression::LITERALS[expr_markup]
|
||||||
elsif cache
|
elsif cache
|
||||||
@name = cache[expr_markup] || (cache[expr_markup] = VariableLookup.parse(expr_markup, ss, cache).freeze)
|
@name = cache[expr_markup] || (cache[expr_markup] = VariableLookup.parse_simple(expr_markup, ss, cache).freeze)
|
||||||
else
|
else
|
||||||
@name = VariableLookup.parse(expr_markup, ss || StringScanner.new(""), nil).freeze
|
@name = VariableLookup.parse_simple(expr_markup, ss || StringScanner.new(""), nil).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
# End of markup? No filters.
|
# End of markup? No filters.
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ module Liquid
|
|||||||
new(markup, string_scanner, cache)
|
new(markup, string_scanner, cache)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Fast parse that skips simple_lookup? check — caller guarantees simple identifier chain
|
||||||
|
def self.parse_simple(markup, string_scanner = nil, cache = nil)
|
||||||
|
new(markup, string_scanner, cache, true)
|
||||||
|
end
|
||||||
|
|
||||||
# Fast manual scanner replacing markup.scan(VariableParser)
|
# Fast manual scanner replacing markup.scan(VariableParser)
|
||||||
# VariableParser = /\[(?>[^\[\]]+|\g<0>)*\]|[\w-]+\??/
|
# VariableParser = /\[(?>[^\[\]]+|\g<0>)*\]|[\w-]+\??/
|
||||||
# Splits "product.variants[0].title" into ["product", "variants", "[0]", "title"]
|
# Splits "product.variants[0].title" into ["product", "variants", "[0]", "title"]
|
||||||
@@ -93,9 +98,9 @@ module Liquid
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(markup, string_scanner = StringScanner.new(""), cache = nil)
|
def initialize(markup, string_scanner = StringScanner.new(""), cache = nil, simple = false)
|
||||||
# Fast path: simple identifier chain without brackets
|
# Fast path: simple identifier chain without brackets
|
||||||
if self.class.simple_lookup?(markup)
|
if simple || self.class.simple_lookup?(markup)
|
||||||
dot_pos = markup.index('.')
|
dot_pos = markup.index('.')
|
||||||
if dot_pos.nil?
|
if dot_pos.nil?
|
||||||
@name = markup
|
@name = markup
|
||||||
|
|||||||
Reference in New Issue
Block a user