Skip to content
Permalink
Browse files

reduce object allocations in utc_offset

`try` allocates an array on every call, we should avoid calling it in
hotspots.  This reduced AttributeMethodsTest#test_setting_time_zone_aware_attribute_with_string
from 18k allocations to 14k
  • Loading branch information
tenderlove committed Aug 30, 2014
1 parent 5e51bdd commit 365aa654d8bbe2889b75df2f5147bc25c54fa751
Showing with 2 additions and 2 deletions.
  1. +2 −2 activesupport/lib/active_support/values/time_zone.rb
@@ -276,8 +276,8 @@ def utc_offset
if @utc_offset
@utc_offset
else
@current_period ||= tzinfo.try(:current_period)
@current_period.try(:utc_offset)
@current_period ||= tzinfo.current_period if tzinfo
@current_period.utc_offset if @current_period
end
end

1 comment on commit 365aa65

@jonatack

This comment has been minimized.

Copy link
Contributor

jonatack commented on 365aa65 Aug 30, 2014

👍 💜

Please sign in to comment.
You can’t perform that action at this time.