]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: avoid unnecessary memory allocation in Writev
authorMatthew Dempsky <mdempsky@google.com>
Tue, 16 Apr 2019 22:52:05 +0000 (15:52 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 17 Apr 2019 00:05:41 +0000 (00:05 +0000)
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>
src/internal/poll/writev.go

index 04e3522d8a19a290ee6defecf50c4c55b3857858..a48a38be0846d27fc3766b07374c267b984c2655 100644 (file)
@@ -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)