aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2015-01-22 17:35:19 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2015-01-22 17:35:19 +0100
commitd3211d76ce666c9fb0a3c69262e4efdb8eee8832 (patch)
treed42b5e6cf36043d49ced3622019306a63e74ded5 /actionpack/lib
parent3d4eaf6dad8186b531d99c4593c8ba626c9ca8cd (diff)
downloadrails-d3211d76ce666c9fb0a3c69262e4efdb8eee8832.tar.gz
rails-d3211d76ce666c9fb0a3c69262e4efdb8eee8832.tar.bz2
rails-d3211d76ce666c9fb0a3c69262e4efdb8eee8832.zip
Speed up `normalize_keys` by removing dup step.
Previously env was duplicated and then had it's keys mutated. This iterates through the hash twice. Using `transform_keys`, duplication and key mutation is a single iteration. `convert_symbols` was renamed to `http_header_format`.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/renderer.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/actionpack/lib/action_controller/renderer.rb b/actionpack/lib/action_controller/renderer.rb
index a122954968..e8b29c5b5e 100644
--- a/actionpack/lib/action_controller/renderer.rb
+++ b/actionpack/lib/action_controller/renderer.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/hash/keys'
+
module ActionController
# ActionController::Renderer allows to render arbitrary templates
# without requirement of being in controller actions.
@@ -71,20 +73,15 @@ module ActionController
private
def normalize_keys(env)
- env.dup.tap do |new_env|
- convert_symbols! new_env
+ http_header_format(env).tap do |new_env|
handle_method_key! new_env
handle_https_key! new_env
end
end
- def convert_symbols!(env)
- env.keys.each do |key|
- if key.is_a? Symbol
- value = env.delete key
- key = key.to_s.upcase
- env[key] = value
- end
+ def http_header_format(env)
+ env.transform_keys do |key|
+ key.is_a?(Symbol) ? key.to_s.upcase : key
end
end