fast-path simple if truthiness: use byte scanner before SIMPLE_CONDITION regex

This commit is contained in:
Tobi Lutke
2026-03-11 08:36:28 -04:00
parent b03adefb1c
commit 03a1977ffe
+5
View File
@@ -89,6 +89,11 @@ module Liquid
SIMPLE_CONDITION = /\A\s*(#{QuotedFragment})\s*(?:([=!<>a-z_]+)\s*(#{QuotedFragment}))?\s*\z/o
def lax_parse(markup)
# Fastest path: simple identifier truthiness like "product.available" or "forloop.first"
if (simple = Variable.simple_variable_markup(markup))
return Condition.new(parse_expression(simple))
end
# Fast path: simple condition without and/or
if !markup.include?(' and ') && !markup.include?(' or ') && markup =~ SIMPLE_CONDITION
return Condition.new(