From cb162195529655c40e0db82b13eeedd062a1745d Mon Sep 17 00:00:00 2001 From: Michael Go Date: Tue, 22 Oct 2024 17:06:20 -0300 Subject: [PATCH 1/2] faster BlockBody variable matching --- lib/liquid/block_body.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index ec40e2129..964758b65 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -246,10 +246,16 @@ def render_node(context, output, node) end def create_variable(token, parse_context) - if token =~ ContentOfVariable - markup = Regexp.last_match(1) + if token.end_with?("}}") + i = 2 + i = 3 if token[i] == "-" + parse_end = token.length - 3 + parse_end -= 1 if token[parse_end] == "-" + + markup = token[i..parse_end] return Variable.new(markup, parse_context) end + BlockBody.raise_missing_variable_terminator(token, parse_context) end From fb6ac72520c20b8e225da2f4853aff1f7a1a59dc Mon Sep 17 00:00:00 2001 From: Michael Go Date: Fri, 25 Oct 2024 15:29:24 -0300 Subject: [PATCH 2/2] use byteslice to create Variable BlockBody --- lib/liquid/block_body.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 964758b65..816c2bc62 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -251,8 +251,9 @@ def create_variable(token, parse_context) i = 3 if token[i] == "-" parse_end = token.length - 3 parse_end -= 1 if token[parse_end] == "-" + markup_end = parse_end - i + 1 + markup = markup_end <= 0 ? "" : token.byteslice(i, markup_end) - markup = token[i..parse_end] return Variable.new(markup, parse_context) end