From c4e5db4d451e1537ab96405193150e3785f3ecf9 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Wed, 7 Aug 2013 17:15:58 +0200 Subject: Unify AS::TZ's lazy init maps. There's no point in having 2 almost identical (@lazy_zones_map and @zones_map) lazy initialized TZ instance caches. --- activesupport/lib/active_support/values/time_zone.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 2c78fe3ee8..b8e6b06087 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -185,6 +185,8 @@ module ActiveSupport UTC_OFFSET_WITH_COLON = '%s%02d:%02d' UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '') + @lazy_zones_map = ThreadSafe::Cache.new + # Assumes self represents an offset from UTC in seconds (as returned from # Time#utc_offset) and turns this into an +HH:MM formatted string. # @@ -363,11 +365,8 @@ module ActiveSupport def zones_map @zones_map ||= begin - map = {} - MAPPING.each_key do |place| - map[place] = lazy_zones_map.fetch(place) { create(place) } - end - map + MAPPING.each_key {|place| self[place]} # load all the zones + @lazy_zones_map end end @@ -415,10 +414,7 @@ module ActiveSupport def lazy_zones_map require_tzinfo - - @lazy_zones_map ||= ThreadSafe::Cache.new do |hash, place| - hash[place] = create(place) if MAPPING.has_key?(place) - end + @lazy_zones_map end end -- cgit v1.2.3