From beadf433c37498dafc6748cc510eeab2636b5be3 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 2 Mar 2019 11:14:33 -0800 Subject: [PATCH] os/exec: provide map size hint in dedupEnvCase MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The common case is that most env vars are distinct; optimize for that. name old time/op new time/op delta ExecEcho-8 2.16ms ± 3% 2.14ms ± 1% ~ (p=0.315 n=10+10) name old alloc/op new alloc/op delta ExecEcho-8 7.87kB ± 0% 6.35kB ± 0% -19.31% (p=0.000 n=9+10) name old allocs/op new allocs/op delta ExecEcho-8 72.0 ± 0% 69.0 ± 0% -4.17% (p=0.000 n=10+10) Change-Id: I42bb696c6862f2ea12c5cbd2f24c64336a7a759a Reviewed-on: https://go-review.googlesource.com/c/164960 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/exec/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index 1aa3ab93dc..7b2b2ebd92 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -713,7 +713,7 @@ func dedupEnv(env []string) []string { // If caseInsensitive is true, the case of keys is ignored. func dedupEnvCase(caseInsensitive bool, env []string) []string { out := make([]string, 0, len(env)) - saw := map[string]int{} // key => index into out + saw := make(map[string]int, len(env)) // key => index into out for _, kv := range env { eq := strings.Index(kv, "=") if eq < 0 { -- 2.48.1