Skip to content
Snippets Groups Projects
Commit 83b53527 authored by 1911860538's avatar 1911860538 Committed by Jorropo
Browse files

net/http: replace map lookup with switch for scheme port

Improve scheme port lookup by replacing map with switch, reducing overhead and improving performance.

Change-Id: I45c790da15e237d5f32c50d342b3713b98fd2ffa
GitHub-Last-Rev: 4c02e4cabf181b365fbf2b722e3051625a289527
GitHub-Pull-Request: golang/go#73422
Reviewed-on: https://go-review.googlesource.com/c/go/+/666356


Reviewed-by: default avatarDamien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent 8a85a2e7
No related branches found
No related tags found
No related merge requests found
...@@ -2931,11 +2931,17 @@ func (pc *persistConn) closeLocked(err error) { ...@@ -2931,11 +2931,17 @@ func (pc *persistConn) closeLocked(err error) {
pc.mutateHeaderFunc = nil pc.mutateHeaderFunc = nil
} }
var portMap = map[string]string{ func schemePort(scheme string) string {
"http": "80", switch scheme {
"https": "443", case "http":
"socks5": "1080", return "80"
"socks5h": "1080", case "https":
return "443"
case "socks5", "socks5h":
return "1080"
default:
return ""
}
} }
func idnaASCIIFromURL(url *url.URL) string { func idnaASCIIFromURL(url *url.URL) string {
...@@ -2950,7 +2956,7 @@ func idnaASCIIFromURL(url *url.URL) string { ...@@ -2950,7 +2956,7 @@ func idnaASCIIFromURL(url *url.URL) string {
func canonicalAddr(url *url.URL) string { func canonicalAddr(url *url.URL) string {
port := url.Port() port := url.Port()
if port == "" { if port == "" {
port = portMap[url.Scheme] port = schemePort(url.Scheme)
} }
return net.JoinHostPort(idnaASCIIFromURL(url), port) return net.JoinHostPort(idnaASCIIFromURL(url), port)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment