From 274f07880604576c745e431a3e41d6fe97bede43 Mon Sep 17 00:00:00 2001 From: Richard Monette Date: Tue, 12 Mar 2019 17:28:16 -0400 Subject: [PATCH] defer hash allocation in parse_filter_expressions add exploration of GC object allocation remove performance test can actually remove one more if branch use named locals to improve readability --- lib/liquid/variable.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index c31bffe5..717b1a2a 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -95,16 +95,17 @@ module Liquid def parse_filter_expressions(filter_name, unparsed_args) filter_args = [] - keyword_args = {} + keyword_args = nil unparsed_args.each do |a| if matches = a.match(JustTagAttributes) + keyword_args ||= {} keyword_args[matches[1]] = Expression.parse(matches[2]) else filter_args << Expression.parse(a) end end result = [filter_name, filter_args] - result << keyword_args unless keyword_args.empty? + result << keyword_args if keyword_args result end