diff options
author | thedarkone <thedarkone2@gmail.com> | 2013-08-07 15:11:03 +0200 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2013-08-07 15:11:03 +0200 |
commit | 548910a67a194d5daf588e3d9a8441a941809a7c (patch) | |
tree | 5990b2a6960c4140b9c269275e0f6ee8530d453e /activesupport/lib/active_support/values | |
parent | b7f2ccd77ac6767b89908523cc4a4ee34fa9f145 (diff) | |
download | rails-548910a67a194d5daf588e3d9a8441a941809a7c.tar.gz rails-548910a67a194d5daf588e3d9a8441a941809a7c.tar.bz2 rails-548910a67a194d5daf588e3d9a8441a941809a7c.zip |
Use TS::Cache instead plain Hash in TimeZone.
Plain ruby Hashes are not thread safe.
Diffstat (limited to 'activesupport/lib/active_support/values')
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 3cf82a24b9..2c78fe3ee8 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -1,3 +1,4 @@ +require 'thread_safe' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/try' @@ -362,10 +363,11 @@ module ActiveSupport def zones_map @zones_map ||= begin - new_zones_names = MAPPING.keys - lazy_zones_map.keys - new_zones = Hash[new_zones_names.map { |place| [place, create(place)] }] - - lazy_zones_map.merge(new_zones) + map = {} + MAPPING.each_key do |place| + map[place] = lazy_zones_map.fetch(place) { create(place) } + end + map end end @@ -414,7 +416,7 @@ module ActiveSupport def lazy_zones_map require_tzinfo - @lazy_zones_map ||= Hash.new do |hash, place| + @lazy_zones_map ||= ThreadSafe::Cache.new do |hash, place| hash[place] = create(place) if MAPPING.has_key?(place) end end |