Permalink
Browse files

reduce hash lookups and disconnect normalize_port from the options hash

  • Loading branch information...
1 parent eec571f commit a6f30bea06083228739150d3aa717af60dff7fc9 @tenderlove tenderlove committed Jun 11, 2014
Showing with 9 additions and 9 deletions.
  1. +9 −9 actionpack/lib/action_dispatch/http/url.rb
@@ -81,16 +81,16 @@ def build_host_url(options)
options[:protocol] = normalize_protocol(options)
options[:host] = normalize_host(options)
- options[:port] = normalize_port(options)
- result = options[:protocol]
+ result = options[:protocol].dup
if options[:user] && options[:password]
result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
end
result << options[:host]
- result << ":#{options[:port]}" if options[:port]
+ port = normalize_port(options[:port], options[:protocol])
+ result << ":#{port}" if port
result
end
@@ -132,16 +132,16 @@ def normalize_host(options)
host
end
- def normalize_port(options)
- return nil if options[:port].nil? || options[:port] == false
+ def normalize_port(port, protocol)
+ return nil if port.nil? || port == false
- case options[:protocol]
+ case protocol
when "//"
- options[:port]
+ port
when "https://"
- options[:port].to_i == 443 ? nil : options[:port]
+ port.to_i == 443 ? nil : port
else
- options[:port].to_i == 80 ? nil : options[:port]
+ port.to_i == 80 ? nil : port
end
end
end

0 comments on commit a6f30be

Please sign in to comment.