Skip to content

Commit

Permalink
Merge pull request #1606 from Watson1978/performance-lexer-tokenize
Browse files Browse the repository at this point in the history
Increase performance in Liquid::Lexer#tokenize
  • Loading branch information
dylanahsmith committed Aug 24, 2022
2 parents f1846d6 + 7611463 commit 98e146e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/liquid/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Lexer
IDENTIFIER = /[a-zA-Z_][\w-]*\??/
SINGLE_STRING_LITERAL = /'[^\']*'/
DOUBLE_STRING_LITERAL = /"[^\"]*"/
STRING_LITERAL = Regexp.union(SINGLE_STRING_LITERAL, DOUBLE_STRING_LITERAL)
NUMBER_LITERAL = /-?\d+(\.\d+)?/
DOTDOT = /\.\./
COMPARISON_OPERATOR = /==|!=|<>|<=?|>=?|contains(?=\s)/
Expand All @@ -35,9 +36,7 @@ def tokenize
break if @ss.eos?
tok = if (t = @ss.scan(COMPARISON_OPERATOR))
[:comparison, t]
elsif (t = @ss.scan(SINGLE_STRING_LITERAL))
[:string, t]
elsif (t = @ss.scan(DOUBLE_STRING_LITERAL))
elsif (t = @ss.scan(STRING_LITERAL))
[:string, t]
elsif (t = @ss.scan(NUMBER_LITERAL))
[:number, t]
Expand Down

0 comments on commit 98e146e

Please sign in to comment.