From: Matthew Dempsky Date: Tue, 16 Apr 2019 22:52:05 +0000 (-0700) Subject: internal/poll: avoid unnecessary memory allocation in Writev X-Git-Tag: go1.13beta1~656 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=33e5da48d5d22a722f2363b15e2d53061fb71cf4;p=gostls13.git internal/poll: avoid unnecessary memory allocation in Writev Writev was allocating a new []syscall.Iovec every call, rather than reusing the cached copy available at *fd.iovec. Fixes #26663. Change-Id: I5967b0d82dc671ce0eaf4ec36cc2a0e46eadde02 Reviewed-on: https://go-review.googlesource.com/c/go/+/172419 Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/internal/poll/writev.go b/src/internal/poll/writev.go index 04e3522d8a..a48a38be08 100644 --- a/src/internal/poll/writev.go +++ b/src/internal/poll/writev.go @@ -51,7 +51,10 @@ func (fd *FD) Writev(v *[][]byte) (int64, error) { if len(iovecs) == 0 { break } - fd.iovecs = &iovecs // cache + if fd.iovecs == nil { + fd.iovecs = new([]syscall.Iovec) + } + *fd.iovecs = iovecs // cache var wrote uintptr wrote, err = writev(fd.Sysfd, iovecs)