Skip to content

Commit

Permalink
Optimize I18n::Locale::Fallbacks#compute
Browse files Browse the repository at this point in the history
  • Loading branch information
uiur committed Apr 26, 2024
1 parent 7842cab commit a295dba
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/i18n/locale/fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@ def inspect
protected

def compute(tags, include_defaults = true, exclude = [])
result = Array(tags).flat_map do |tag|
tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym } - exclude
tags.each { |_tag| tags += compute(@map[_tag], false, exclude + tags) if @map[_tag] }
tags
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]
end

result.push(*defaults) if include_defaults
result.uniq!
result.compact!
Expand Down

0 comments on commit a295dba

Please sign in to comment.