Reduce allocations from where-filter (#7653)

Merge pull request 7653
This commit is contained in:
Ashwin Maroli 2019-05-16 22:08:53 +05:30 committed by jekyllbot
parent 2d3c030fac
commit ed385ba264
1 changed files with 14 additions and 3 deletions

View File

@ -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 ||= {}