mirror of
https://github.com/kemko/liquid.git
synced 2026-01-04 01:05:40 +03:00
Use #each to avoid extra allocations
This commit is contained in:
@@ -37,7 +37,10 @@ module Liquid
|
||||
if val.instance_of?(String)
|
||||
val.length
|
||||
elsif val.instance_of?(Array) || val.instance_of?(Hash)
|
||||
val.reduce(0) { |n, child| n + assign_score_of(child) }
|
||||
sum = 1
|
||||
# Uses #each to avoid extra allocations.
|
||||
val.each { |child| sum += assign_score_of(child) }
|
||||
sum
|
||||
else
|
||||
1
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user