more micro optimization

This commit is contained in:
Michael Go
2024-10-24 22:34:01 -03:00
parent 50f7c62714
commit 7868aee751
+3 -8
View File
@@ -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)