Skip to content

Commit 33e5da4

Browse files
committed
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 <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent d7df9de commit 33e5da4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/internal/poll/writev.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ func (fd *FD) Writev(v *[][]byte) (int64, error) {
5151
if len(iovecs) == 0 {
5252
break
5353
}
54-
fd.iovecs = &iovecs // cache
54+
if fd.iovecs == nil {
55+
fd.iovecs = new([]syscall.Iovec)
56+
}
57+
*fd.iovecs = iovecs // cache
5558

5659
var wrote uintptr
5760
wrote, err = writev(fd.Sysfd, iovecs)

0 commit comments

Comments
 (0)