use frozen EMPTY_ARRAY/EMPTY_HASH for Context @filters/@disabled_tags

This commit is contained in:
Tobi Lutke
2026-04-04 17:42:32 -07:00
committed by Chris Pak
parent 1f309b19a7
commit e1a0e7e716
+3 -2
View File
@@ -36,9 +36,9 @@ module Liquid
@resource_limits = resource_limits || ResourceLimits.new(environment.default_resource_limits) @resource_limits = resource_limits || ResourceLimits.new(environment.default_resource_limits)
@base_scope_depth = 0 @base_scope_depth = 0
@interrupts = [] @interrupts = []
@filters = [] @filters = Const::EMPTY_ARRAY
@global_filter = nil @global_filter = nil
@disabled_tags = {} @disabled_tags = Const::EMPTY_HASH
# Instead of constructing new StringScanner objects for each Expression parse, # Instead of constructing new StringScanner objects for each Expression parse,
# we recycle the same one. # we recycle the same one.
@@ -245,6 +245,7 @@ module Liquid
end end
def with_disabled_tags(tag_names) def with_disabled_tags(tag_names)
@disabled_tags = {} if @disabled_tags.frozen?
tag_names.each do |name| tag_names.each do |name|
@disabled_tags[name] = @disabled_tags.fetch(name, 0) + 1 @disabled_tags[name] = @disabled_tags.fetch(name, 0) + 1
end end