Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize I18n::Locale::Fallbacks#[] for recursive locale mappings #692

Merged
merged 3 commits into from May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/i18n/locale/fallbacks.rb
Expand Up @@ -90,11 +90,13 @@ def inspect
protected

def compute(tags, include_defaults = true, exclude = [])
result = Array(tags).flat_map do |tag|
result = []
Array(tags).each 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
result += tags
tags.each { |_tag| result += compute(@map[_tag], false, exclude + result) if @map[_tag] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is prune and exclude more when calling recursion.
result is already computed so it can exclude result within following recursions.

end

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