aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2019-03-03 15:30:24 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2019-03-03 17:45:46 +0000
commit59712fd03d37c0d17cce9f6605a9cc87fa0d4870 (patch)
tree41c4383492f622d75e4ca7e8c6eb0d62e0084707 /src/os/exec
parentec01d8f74bf60c0fe52335bf8bcf475e3653822d (diff)
downloadgo-59712fd03d37c0d17cce9f6605a9cc87fa0d4870.tar.xz
os/exec: preallocate for Cmd.childFiles
We're always going to add stdin, stdout, and stderr to childFiles, so its length will be at least three. The final length will be those three elements plus however many files were given via ExtraFiles. Allocate for that final length directly, saving two slice growth allocs in the common case where ExtraFiles is empty. name old time/op new time/op delta ExecEcho-8 435µs ± 0% 435µs ± 0% ~ (p=0.394 n=6+6) name old alloc/op new alloc/op delta ExecEcho-8 6.39kB ± 0% 6.37kB ± 0% -0.39% (p=0.002 n=6+6) name old allocs/op new allocs/op delta ExecEcho-8 36.0 ± 0% 34.0 ± 0% -5.56% (p=0.002 n=6+6) Change-Id: Ib702c0da1e43f0a55ed937af6d45fca6a170e8f3 Reviewed-on: https://go-review.googlesource.com/c/164898 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/os/exec')
-rw-r--r--src/os/exec/exec.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
index 7b2b2ebd92..30fd64a4b1 100644
--- a/src/os/exec/exec.go
+++ b/src/os/exec/exec.go
@@ -376,6 +376,7 @@ func (c *Cmd) Start() error {
}
}
+ c.childFiles = make([]*os.File, 0, 3+len(c.ExtraFiles))
type F func(*Cmd) (*os.File, error)
for _, setupFd := range []F{(*Cmd).stdin, (*Cmd).stdout, (*Cmd).stderr} {
fd, err := setupFd(c)