diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-18 10:21:15 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-18 10:21:15 -0700 |
commit | dda81cb177078cce44bf2a81a70b0baa5c9d9ad7 (patch) | |
tree | 1a49b2eeb272a6c8e7ce0647988ff3de6d3a6742 /actionpack/lib/action_view | |
parent | 132f3e2d37057eb4de13e32bf52c13097183c622 (diff) | |
download | rails-dda81cb177078cce44bf2a81a70b0baa5c9d9ad7.tar.gz rails-dda81cb177078cce44bf2a81a70b0baa5c9d9ad7.tar.bz2 rails-dda81cb177078cce44bf2a81a70b0baa5c9d9ad7.zip |
lets not invert the hash on every iteration through this loop
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 326d5c1049..1488e72c6e 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -445,6 +445,8 @@ module ActionView #for backwards compatibility with those that didn't add strip_insignificant_zeros to their locale files options[:strip_insignificant_zeros] = true if not options.key?(:strip_insignificant_zeros) + inverted_du = DECIMAL_UNITS.invert + units = options.delete :units unit_exponents = case units when Hash @@ -455,7 +457,7 @@ module ActionView I18n.translate(:"number.human.decimal_units.units", :locale => options[:locale], :raise => true) else raise ArgumentError, ":units must be a Hash or String translation scope." - end.keys.map{|e_name| DECIMAL_UNITS.invert[e_name] }.sort_by{|e| -e} + end.keys.map{|e_name| inverted_du[e_name] }.sort_by{|e| -e} number_exponent = number != 0 ? Math.log10(number.abs).floor : 0 display_exponent = unit_exponents.find{|e| number_exponent >= e } |