don't cache string expressions to be more perfomant

This commit is contained in:
Michael Go
2025-01-07 14:32:07 -04:00
parent 7c8a269b4d
commit 92fa334192
+6 -4
View File
@@ -81,16 +81,18 @@ module Liquid
markup = markup.strip # markup can be a frozen string 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) return CACHE[markup] if CACHE.key?(markup)
CACHE[markup] = inner_parse(markup) CACHE[markup] = inner_parse(markup)
end end
def inner_parse(markup) def inner_parse(markup)
if (markup.start_with?('"') && markup.end_with?('"')) || if (markup.start_with?("(") && markup.end_with?(")")) && markup =~ RANGES_REGEX
(markup.start_with?("'") && markup.end_with?("'"))
return markup[1..-2]
elsif (markup.start_with?("(") && markup.end_with?(")")) && markup =~ RANGES_REGEX
return RangeLookup.parse(Regexp.last_match(1), Regexp.last_match(2)) return RangeLookup.parse(Regexp.last_match(1), Regexp.last_match(2))
end end