Replace manual scan_quoted_string with regex capture groups\n\nResult: {"status":"keep","combined_µs":4102,"parse_µs":2849,"render_µs":1253,"allocations":25535}

This commit is contained in:
Tobi Lutke
2026-03-11 10:41:44 -04:00
parent e15b163f1a
commit fd4a7af290
+7 -10
View File
@@ -142,19 +142,16 @@ module Liquid
end
end
# Regex for quoted string content (without quotes)
SINGLE_QUOTED_CONTENT = /'([^']*)'/
DOUBLE_QUOTED_CONTENT = /"([^"]*)"/
# ── Strings ─────────────────────────────────────────────────────
# Scan a quoted string ('...' or "..."). Returns the content without quotes, or nil.
def scan_quoted_string
b = @ss.peek_byte
return unless b == QUOTE_S || b == QUOTE_D
quote = b
@ss.scan_byte
start = @ss.pos
@ss.scan_byte while (b = @ss.peek_byte) && b != quote
content = @source.byteslice(start, @ss.pos - start)
@ss.scan_byte if @ss.peek_byte == quote # consume closing quote
content
if @ss.scan(SINGLE_QUOTED_CONTENT) || @ss.scan(DOUBLE_QUOTED_CONTENT)
@ss[1]
end
end
# Regex for quoted strings (single or double quoted, including quotes)