Skip to content

Commit

Permalink
Use left recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
uiur committed Apr 26, 2024
1 parent a295dba commit 3d19b68
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/i18n/locale/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ def inspect
protected

def compute(tags, include_defaults = true, exclude = [])
tags = Array(tags).flat_map do |tag|
I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym }
end
tags -= exclude

result = tags
tags.each do |tag|
result += compute(@map[tag], false, exclude + result) if @map[tag]
result = []
Array(tags).each do |tag|
tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym } - exclude
result += tags
tags.each { |_tag| result += compute(@map[_tag], false, exclude + result) if @map[_tag] }
result
end

result.push(*defaults) if include_defaults
Expand Down

0 comments on commit 3d19b68

Please sign in to comment.