Skip to content
Browse files

cache protocol on the stack to reduce options hash lookups

  • Loading branch information...
1 parent 1c432d1 commit aaaff369da1ebc83fe2a202e5bbbd98c1eda2f42 @tenderlove tenderlove committed Jun 11, 2014
Showing with 7 additions and 7 deletions.
  1. +7 −7 actionpack/lib/action_dispatch/http/url.rb
View
14 actionpack/lib/action_dispatch/http/url.rb
@@ -79,17 +79,17 @@ def build_host_url(options)
options[:port] = match[3] unless options.key?(:port)
end
- options[:protocol] = normalize_protocol(options)
- options[:host] = normalize_host(options)
+ protocol = normalize_protocol options[:protocol]
+ options[:host] = normalize_host(options)
- result = options[:protocol].dup
+ result = protocol.dup
if options[:user] && options[:password]
result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
end
result << options[:host]
- normalize_port(options[:port], options[:protocol]) { |port|
+ normalize_port(options[:port], protocol) { |port|
result << ":#{port}"
}
@@ -104,16 +104,16 @@ def same_host?(options)
(options[:subdomain] == true || !options.key?(:subdomain)) && options[:domain].nil?
end
- def normalize_protocol(options)
- case options[:protocol]
+ def normalize_protocol(protocol)
+ case protocol
when nil
"http://"
when false, "//"
"//"
when PROTOCOL_REGEXP
"#{$1}://"
else
- raise ArgumentError, "Invalid :protocol option: #{options[:protocol].inspect}"
+ raise ArgumentError, "Invalid :protocol option: #{protocol.inspect}"
end
end

0 comments on commit aaaff36

Please sign in to comment.
Something went wrong with that request. Please try again.