Skip to content

Commit

Permalink
don't cache string expressions to be more perfomant
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Nov 14, 2024
1 parent e0d54cc commit c0e45c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/liquid/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,18 @@ def parse(markup)

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

if (markup.start_with?('"') && markup.end_with?('"')) ||
(markup.start_with?("'") && markup.end_with?("'"))
return markup[1..-2]
end

return CACHE[markup] if CACHE.key?(markup)

CACHE[markup] = inner_parse(markup)
end

def inner_parse(markup)
if (markup.start_with?('"') && markup.end_with?('"')) ||
(markup.start_with?("'") && markup.end_with?("'"))
return markup[1..-2]
elsif (markup.start_with?("(") && markup.end_with?(")")) && markup =~ RANGES_REGEX
if (markup.start_with?("(") && markup.end_with?(")")) && markup =~ RANGES_REGEX
return RangeLookup.parse(Regexp.last_match(1), Regexp.last_match(2))
end

Expand Down

0 comments on commit c0e45c1

Please sign in to comment.