mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Cache no-arg filter tuples [name, EMPTY_ARRAY] — reuse frozen tuples across templates\n\nResult: {"status":"keep","combined_µs":4147,"parse_µs":2992,"render_µs":1155,"allocations":24881}
This commit is contained in:
@@ -71,6 +71,9 @@ module Liquid
|
||||
end
|
||||
end
|
||||
|
||||
# Cache for [filtername, EMPTY_ARRAY] tuples — avoids repeated array creation
|
||||
NO_ARG_FILTER_CACHE = Hash.new { |h, k| h[k] = [k, Const::EMPTY_ARRAY].freeze }
|
||||
|
||||
FilterMarkupRegex = /#{FilterSeparator}\s*(.*)/om
|
||||
FilterParser = /(?:\s+|#{QuotedFragment}|#{ArgumentSeparator})+/o
|
||||
FilterArgsRegex = /(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o
|
||||
@@ -291,7 +294,7 @@ module Liquid
|
||||
@filters << [filtername, filter_args]
|
||||
else
|
||||
# No args — add as simple filter
|
||||
@filters << [filtername, Const::EMPTY_ARRAY]
|
||||
@filters << NO_ARG_FILTER_CACHE[filtername]
|
||||
end
|
||||
|
||||
# Skip whitespace between filters
|
||||
|
||||
Reference in New Issue
Block a user