From 548910a67a194d5daf588e3d9a8441a941809a7c Mon Sep 17 00:00:00 2001 From: thedarkone Date: Wed, 7 Aug 2013 15:11:03 +0200 Subject: Use TS::Cache instead plain Hash in TimeZone. Plain ruby Hashes are not thread safe. --- activesupport/lib/active_support/values/time_zone.rb | 12 +++++++----- 1 file 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 -- cgit v1.2.3