aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2014-08-14 12:29:25 -0500
committerschneems <richard.schneeman@gmail.com>2014-08-14 12:46:06 -0500
commit4d47220d7c4d07d23e4a1f01bdd6d86fa76237ca (patch)
tree6483f759a2a46f3c2c773d19768a70f36e45d0f0 /actionview/lib
parent71e8f199d75fcad804c6a36e089b6b8fb4071192 (diff)
downloadrails-4d47220d7c4d07d23e4a1f01bdd6d86fa76237ca.tar.gz
rails-4d47220d7c4d07d23e4a1f01bdd6d86fa76237ca.tar.bz2
rails-4d47220d7c4d07d23e4a1f01bdd6d86fa76237ca.zip
Perf optimization for `url_for` called w/ Hash
Benchmarking the existing code: ```ruby { :only_path => options[:host].nil? }.merge!(options.symbolize_keys)) ``` Against optimized code, that does not require a new hash or a merge: ```ruby options = options.symbolize_keys options[:only_path] = options[:host].nil? unless options.key?(:only_path) options ``` We see a statistically significant performance gain: ![](https://www.dropbox.com/s/onocpc0zfw4kjxl/Screenshot%202014-08-14%2012.45.30.png?dl=1) Updated to not mutate incoming parameters
Diffstat (limited to 'actionview/lib')
-rw-r--r--actionview/lib/action_view/routing_url_for.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/actionview/lib/action_view/routing_url_for.rb b/actionview/lib/action_view/routing_url_for.rb
index 881a123572..75febb8652 100644
--- a/actionview/lib/action_view/routing_url_for.rb
+++ b/actionview/lib/action_view/routing_url_for.rb
@@ -82,7 +82,9 @@ module ActionView
when nil
super({:only_path => true})
when Hash
- super({ :only_path => options[:host].nil? }.merge!(options.symbolize_keys))
+ options = options.symbolize_keys
+ options[:only_path] = options[:host].nil? unless options.key?(:only_path)
+ super(options)
when :back
_back_url
when Symbol