Skip to content

Commit

Permalink
faster variable lookup parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Nov 5, 2024
1 parent 5a255ef commit 7538bcb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/liquid/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Expression2
def self.parse(markup)
return nil unless markup

markup = markup.strip
markup = markup.strip # markup can be a frozen string

if (markup.start_with?('"') && markup.end_with?('"')) ||
(markup.start_with?("'") && markup.end_with?("'"))
Expand All @@ -90,7 +90,6 @@ def self.parse(markup)

def self.parse_number(markup)
ss = StringScanner.new(markup)

is_integer = true
last_dot_pos = nil
num_end_pos = nil
Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/variable_lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(markup)

name = lookups.shift
if name&.start_with?('[') && name&.end_with?(']')
name = Expression.parse(name[1..-2])
name = Expression.parse(name.byteslice(1, name.length - 2))
end
@name = name

Expand All @@ -25,7 +25,7 @@ def initialize(markup)
@lookups.each_index do |i|
lookup = lookups[i]
if lookup&.start_with?('[') && lookup&.end_with?(']')
lookups[i] = Expression.parse(lookup[1..-2])
lookups[i] = Expression.parse(lookup.byteslice(1, lookup.length - 2))
elsif COMMAND_METHODS.include?(lookup)
@command_flags |= 1 << i
end
Expand Down

0 comments on commit 7538bcb

Please sign in to comment.