diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index f971b0f7..71331ef5 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -12,78 +12,6 @@ module Liquid TAGSTART = "{%" VARSTART = "{{" - # Fast manual tag token parser - avoids regex MatchData allocation - # Parses "{%[-] tag_name markup [-]%}" and returns [pre_ws, tag_name, post_ws, markup] or nil - NEWLINE_BYTE = 10 # "\n".ord - - class << self - attr_reader :_last_markup, :_last_newlines - end - - # Fast manual tag token parser - avoids regex MatchData allocation - # Parses "{%[-] tag_name markup [-]%}" directly into parse_context fields - # Returns tag_name string or nil on failure. Sets @_tag_markup and @_tag_newlines. - def self.parse_tag_token(token) - # token starts with "{%" - pos = 2 - len = token.length - newlines = 0 - - # skip optional whitespace control '-' - pos += 1 if pos < len && token.getbyte(pos) == 45 # '-' - - # skip pre-whitespace, counting newlines - while pos < len - b = token.getbyte(pos) - if b == NEWLINE_BYTE - newlines += 1 - pos += 1 - elsif b == 32 || b == 9 || b == 13 # space, tab, \r - pos += 1 - else - break - end - end - - # parse tag name: # or \w+ - name_start = pos - if pos < len && token.getbyte(pos) == 35 # '#' - pos += 1 - else - while pos < len - b = token.getbyte(pos) - break unless (b >= 97 && b <= 122) || (b >= 65 && b <= 90) || (b >= 48 && b <= 57) || b == 95 - pos += 1 - end - end - return nil if pos == name_start - tag_name = token.byteslice(name_start, pos - name_start) - - # skip post-whitespace, counting newlines - while pos < len - b = token.getbyte(pos) - if b == NEWLINE_BYTE - newlines += 1 - pos += 1 - elsif b == 32 || b == 9 || b == 13 - pos += 1 - else - break - end - end - - # the rest is markup, up to optional '-' and '%}' - markup_end = len - 2 - markup_end -= 1 if markup_end > pos && token.getbyte(markup_end - 1) == 45 - markup = pos >= markup_end ? "" : token.byteslice(pos, markup_end - pos) - - # Store extra results to avoid array allocation for the return value - @_last_markup = markup - @_last_newlines = newlines - - tag_name - end - attr_reader :nodelist def initialize diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index 242141be..70d6a16f 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -85,8 +85,6 @@ module Liquid Condition.parse_expression(parse_context, markup, safe: safe) end - # Fast path regex for simple conditions: "expr", "expr op expr" (no and/or) - 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"