aboutsummaryrefslogtreecommitdiff
path: root/src/net/http
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-04-29 16:45:05 -0700
committerMatthew Dempsky <mdempsky@google.com>2020-04-30 00:13:38 +0000
commit844b410922b2ea7d22b651c536178e79696749f6 (patch)
tree49a8c43fc8715d0b1b34c82fcb91a9d79114b5cc /src/net/http
parenta7e539619e5a73d9330f1698d710d99273651768 (diff)
downloadgo-844b410922b2ea7d22b651c536178e79696749f6.tar.xz
net/http/cgi: replace constant map with switch statement
The switch statement can be statically optimized by the compiler, whereas similarly optimizing the map index expression would require additional compiler analysis to detect the map is never mutated. Updates #10848. Change-Id: I2fc70d4a34dc545677b99f218b51023c7891bbbd Reviewed-on: https://go-review.googlesource.com/c/go/+/231041 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http')
-rw-r--r--src/net/http/cgi/host.go29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/net/http/cgi/host.go b/src/net/http/cgi/host.go
index 58e9f7132a..215bb83a39 100644
--- a/src/net/http/cgi/host.go
+++ b/src/net/http/cgi/host.go
@@ -32,16 +32,23 @@ import (
var trailingPort = regexp.MustCompile(`:([0-9]+)$`)
-var osDefaultInheritEnv = map[string][]string{
- "darwin": {"DYLD_LIBRARY_PATH"},
- "freebsd": {"LD_LIBRARY_PATH"},
- "hpux": {"LD_LIBRARY_PATH", "SHLIB_PATH"},
- "irix": {"LD_LIBRARY_PATH", "LD_LIBRARYN32_PATH", "LD_LIBRARY64_PATH"},
- "linux": {"LD_LIBRARY_PATH"},
- "openbsd": {"LD_LIBRARY_PATH"},
- "solaris": {"LD_LIBRARY_PATH", "LD_LIBRARY_PATH_32", "LD_LIBRARY_PATH_64"},
- "windows": {"SystemRoot", "COMSPEC", "PATHEXT", "WINDIR"},
-}
+var osDefaultInheritEnv = func() []string {
+ switch runtime.GOOS {
+ case "darwin":
+ return []string{"DYLD_LIBRARY_PATH"}
+ case "linux", "freebsd", "openbsd":
+ return []string{"LD_LIBRARY_PATH"}
+ case "hpux":
+ return []string{"LD_LIBRARY_PATH", "SHLIB_PATH"}
+ case "irix":
+ return []string{"LD_LIBRARY_PATH", "LD_LIBRARYN32_PATH", "LD_LIBRARY64_PATH"}
+ case "solaris":
+ return []string{"LD_LIBRARY_PATH", "LD_LIBRARY_PATH_32", "LD_LIBRARY_PATH_64"}
+ case "windows":
+ return []string{"SystemRoot", "COMSPEC", "PATHEXT", "WINDIR"}
+ }
+ return nil
+}()
// Handler runs an executable in a subprocess with a CGI environment.
type Handler struct {
@@ -183,7 +190,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
}
}
- for _, e := range osDefaultInheritEnv[runtime.GOOS] {
+ for _, e := range osDefaultInheritEnv {
if v := os.Getenv(e); v != "" {
env = append(env, e+"="+v)
}