Skip to content

Commit

Permalink
Unify AS::TZ's lazy init maps.
Browse files Browse the repository at this point in the history
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 c4e5db4
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions activesupport/lib/active_support/values/time_zone.rb
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c4e5db4

Please sign in to comment.