From ed385ba264e82008fa37b4fad2eac9c353826213 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 16 May 2019 22:08:53 +0530 Subject: [PATCH] Reduce allocations from where-filter (#7653) Merge pull request 7653 --- lib/jekyll/filters.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 055a3e5e..cec65ba3 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -326,20 +326,31 @@ module Jekyll end # `where` filter helper + # + # rubocop:disable Metrics/CyclomaticComplexity + # rubocop:disable Metrics/PerceivedComplexity def compare_property_vs_target(property, target) case target when NilClass return true if property.nil? when Liquid::Expression::MethodLiteral # `empty` or `blank` - return true if Array(property).join == target.to_s + target = target.to_s + return true if property == target || Array(property).join == target else - Array(property).each do |prop| - return true if prop.to_s == target.to_s + target = target.to_s + if property.is_a? String + return true if property == target + else + Array(property).each do |prop| + return true if prop.to_s == target + end end end false end + # rubocop:enable Metrics/CyclomaticComplexity + # rubocop:enable Metrics/PerceivedComplexity def item_property(item, property) @item_property_cache ||= {}