Permalink
Browse files

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.
  • Loading branch information...
thedarkone committed Aug 7, 2013
1 parent 548910a commit c4e5db4d451e1537ab96405193150e3785f3ecf9
Showing with 5 additions and 9 deletions.
  1. +5 −9 activesupport/lib/active_support/values/time_zone.rb
@@ -185,6 +185,8 @@ class TimeZone
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 @@ def all
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 @@ def lookup(name)
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

0 comments on commit c4e5db4

Please sign in to comment.