• Alex Brainman's avatar
    internal/poll: remove allocation in windows FD.Writev · ddcb975f
    Alex Brainman authored
    Use closure parameter instead of external variable to
    remove 1 allocation.
    
    I tried to add test, but it is difficult to add something simple
    and not flake here. I did test this with:
    
    diff --git a/src/net/writev_test.go b/src/net/writev_test.go
    index 4c05be4..e417d68 100644
    --- a/src/net/writev_test.go
    +++ b/src/net/writev_test.go
    @@ -99,6 +99,15 @@ func TestBuffers_WriteTo(t *testing.T) {
     	}
     }
    
    +func TestBuffers_WriteToAllocs(t *testing.T) {
    +	allocs := testing.AllocsPerRun(10, func() {
    +		testBuffer_writeTo(t, 10, false)
    +	})
    +	if allocs > 0 {
    +		t.Fatalf("got %v; want 0", allocs)
    +	}
    +}
    +
     func testBuffer_writeTo(t *testing.T, chunks int, useCopy bool) {
     	oldHook := poll.TestHookDidWritev
     	defer func() { poll.TestHookDidWritev = oldHook }()
    
    It makes allocation count go down by 1 after the fix.
    
    Before:
    
    C:\>u:\test -test.v -test.run=WriteToAllocs
    === RUN   TestBuffers_WriteToAllocs
    --- FAIL: TestBuffers_WriteToAllocs (0.05s)
            writev_test.go:107: got 66; want 0
    FAIL
    
    and after:
    
    C:\>u:\test -test.v -test.run=WriteToAllocs
    === RUN   TestBuffers_WriteToAllocs
    --- FAIL: TestBuffers_WriteToAllocs (0.04s)
            writev_test.go:107: got 65; want 0
    FAIL
    
    Thanks to @MichaelMonashev for report and the fix.
    
    Fixes #19222
    
    Change-Id: I0f73cd9e2c8bbaa0653083f81f3ccb83b5ea84e1
    Reviewed-on: https://go-review.googlesource.com/42893Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    ddcb975f
Name
Last commit
Last update
..
export_posix_test.go Loading commit data...
export_test.go Loading commit data...
fd.go Loading commit data...
fd_io_plan9.go Loading commit data...
fd_mutex.go Loading commit data...
fd_mutex_test.go Loading commit data...
fd_plan9.go Loading commit data...
fd_poll_nacl.go Loading commit data...
fd_poll_runtime.go Loading commit data...
fd_posix.go Loading commit data...
fd_posix_test.go Loading commit data...
fd_unix.go Loading commit data...
fd_windows.go Loading commit data...
hook_cloexec.go Loading commit data...
hook_unix.go Loading commit data...
hook_windows.go Loading commit data...
sendfile_bsd.go Loading commit data...
sendfile_linux.go Loading commit data...
sendfile_solaris.go Loading commit data...
sendfile_windows.go Loading commit data...
sock_cloexec.go Loading commit data...
sockopt.go Loading commit data...
sockopt_linux.go Loading commit data...
sockopt_unix.go Loading commit data...
sockopt_windows.go Loading commit data...
sockoptip.go Loading commit data...
strconv.go Loading commit data...
sys_cloexec.go Loading commit data...
writev.go Loading commit data...
writev_test.go Loading commit data...