Skip to content

Commit

Permalink
Merge branch 'pr-51-thread-safety-fix' of github.com:svenfuchs/i18n i…
Browse files Browse the repository at this point in the history
…nto pr-51-thread-safety-fix

* 'pr-51-thread-safety-fix' of github.com:svenfuchs/i18n:
  Initialize global hash during module load
  • Loading branch information
radar committed Oct 1, 2017
2 parents 358249b + 9aabd00 commit 6d2ec72
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/i18n.rb
Expand Up @@ -323,8 +323,10 @@ def handle_exception(handling, exception, locale, key, options)
end
end

@@normalized_key_cache = Concurrent::Hash.new { |h, k| h[k] = Concurrent::Hash.new }

def normalize_key(key, separator)
normalized_key_cache[separator][key] ||=
@@normalized_key_cache[separator][key] ||=
case key
when Array
key.map { |k| normalize_key(k, separator) }.flatten
Expand All @@ -335,10 +337,6 @@ def normalize_key(key, separator)
keys
end
end

def normalized_key_cache
@normalized_key_cache ||= Concurrent::Hash.new { |h,k| h[k] = Concurrent::Hash.new }
end
end

extend Base
Expand Down

0 comments on commit 6d2ec72

Please sign in to comment.