提交 dbb0bd8f 编写于 作者: A Aaron Patterson

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.
上级 73a7b52f
......@@ -33,10 +33,8 @@ def url_for(options)
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 @@ def url_for(options)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册