diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-09 17:31:13 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-09 17:31:13 -0700 |
commit | dbb0bd8f3a43df9881033136421be4ad219b19b5 (patch) | |
tree | 87683270c37e82851abf364e20bde93da4384e10 /actionpack | |
parent | 73a7b52f0182a789bf45d4b0c23384911d1ed034 (diff) | |
download | rails-dbb0bd8f3a43df9881033136421be4ad219b19b5.tar.gz rails-dbb0bd8f3a43df9881033136421be4ad219b19b5.tar.bz2 rails-dbb0bd8f3a43df9881033136421be4ad219b19b5.zip |
skip dealing with params if none are provided
This lets us avoid
1. A slow call to Hash#slice
2. An is_a? test
3. Extra hash allocations (from slice)
4. String allocations
etc.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/url.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb index f33a855bc2..278f534380 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -33,10 +33,8 @@ module ActionDispatch path = options[:script_name].to_s.chomp("/") path << options[:path].to_s - params = options[:params].is_a?(Hash) ? options[:params] : options.slice(:params) - params.reject! { |_,v| v.to_param.nil? } - result = build_host_url(options) + if options[:trailing_slash] if path.include?('?') result << path.sub(/\?/, '/\&') @@ -46,7 +44,16 @@ module ActionDispatch else result << path end - result << "?#{params.to_query}" unless params.empty? + + if options.key? :params + params = options[:params].is_a?(Hash) ? + options[:params] : + { params: options[:params] } + + params.reject! { |_,v| v.to_param.nil? } + result << "?#{params.to_query}" unless params.empty? + end + result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor] result end |