From 7868aee7510fc258a833080f1e1af03fa7a3a516 Mon Sep 17 00:00:00 2001 From: Michael Go Date: Thu, 24 Oct 2024 22:34:01 -0300 Subject: [PATCH] more micro optimization --- lib/liquid/tokenizer.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/liquid/tokenizer.rb b/lib/liquid/tokenizer.rb index fdbcb84c..77c9656e 100644 --- a/lib/liquid/tokenizer.rb +++ b/lib/liquid/tokenizer.rb @@ -15,7 +15,6 @@ module Liquid PERCENTAGE = 37 def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false) - @source = source @line_number = line_number || (line_numbers ? 1 : nil) @for_liquid_tag = for_liquid_tag @ss = StringScanner.new(source) @@ -81,27 +80,23 @@ module Liquid @ss.pos += 2 # it is possible to see a {% before a }} so we need to check for that - byte_a = @ss.peek_byte - @ss.pos += 1 + byte_a = @ss.scan_byte until @ss.eos? while byte_a != OPEN_CURLEY && byte_a != CLOSE_CURLEY && @ss.eos? == false - byte_a = @ss.peek_byte - @ss.pos += 1 + byte_a = @ss.scan_byte end break if @ss.eos? - byte_b = @ss.peek_byte + byte_b = @ss.scan_byte if byte_b != CLOSE_CURLEY && byte_b != PERCENTAGE - @ss.pos += 1 byte_a = byte_b next end if byte_a == CLOSE_CURLEY && byte_b == CLOSE_CURLEY - @ss.pos += 1 return @ss.string.byteslice(start, @ss.pos - start) elsif byte_a == OPEN_CURLEY && byte_b == PERCENTAGE return next_tag_token(start)