aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-08-16 01:33:34 +0100
committerJon Leighton <j@jonathanleighton.com>2011-08-16 01:33:34 +0100
commitbfb9e61a9f12024ebe999216d4d17fdb53765883 (patch)
tree298862aa8628dc8658737b9be159c1a959c31d0f /activesupport
parent6c5f67cac15c43bafcd917c346cccfcf3fa5fb95 (diff)
downloadrails-bfb9e61a9f12024ebe999216d4d17fdb53765883.tar.gz
rails-bfb9e61a9f12024ebe999216d4d17fdb53765883.tar.bz2
rails-bfb9e61a9f12024ebe999216d4d17fdb53765883.zip
Be more lazy about creating time zone objects. Decreases startup time by about 10%. (#734)
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 728921a069..323d5d3df7 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -337,7 +337,12 @@ module ActiveSupport
end
def zones_map
- @zones_map ||= Hash[MAPPING.map { |place, _| [place, create(place)] }]
+ @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)
+ end
end
# Locate a specific time zone object. If the argument is a string, it
@@ -349,7 +354,7 @@ module ActiveSupport
case arg
when String
begin
- zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset }
+ lazy_zones_map[arg] ||= lookup(arg).tap { |tz| tz.utc_offset }
rescue TZInfo::InvalidTimezoneIdentifier
nil
end
@@ -372,6 +377,12 @@ module ActiveSupport
def lookup(name)
(tzinfo = find_tzinfo(name)) && create(tzinfo.name.freeze)
end
+
+ def lazy_zones_map
+ @lazy_zones_map ||= Hash.new do |hash, place|
+ hash[place] = create(place) if MAPPING.has_key?(place)
+ end
+ end
end
end
end