From f11599b0b909a61d575bcea532ee2250f9a682da Mon Sep 17 00:00:00 2001 From: qmuntal Date: Wed, 2 Jul 2025 11:12:28 +0200 Subject: [PATCH] internal/poll: remove handle field from Windows' poll.operation The handle field can be accessed directly wherever needed, there is no need to store it in the operation struct. This skims down the size of os.File by 16 bytes. Change-Id: I87c94cb773437891127b6c36dc7f8883622ffed3 Reviewed-on: https://go-review.googlesource.com/c/go/+/685435 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek Auto-Submit: Michael Knyszek Reviewed-by: Damien Neil --- src/internal/poll/fd_windows.go | 20 +++++++++----------- src/internal/poll/sendfile_windows.go | 3 +-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index f052a2a016..38fecb0e12 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -77,15 +77,14 @@ type operation struct { mode int32 // fields used only by net package - buf syscall.WSABuf - msg windows.WSAMsg - sa syscall.Sockaddr - rsa *syscall.RawSockaddrAny - rsan int32 - handle syscall.Handle - flags uint32 - qty uint32 - bufs []syscall.WSABuf + buf syscall.WSABuf + msg windows.WSAMsg + sa syscall.Sockaddr + rsa *syscall.RawSockaddrAny + rsan int32 + flags uint32 + qty uint32 + bufs []syscall.WSABuf } func (o *operation) setEvent() { @@ -1028,10 +1027,9 @@ func (fd *FD) ConnectEx(ra syscall.Sockaddr) error { func (fd *FD) acceptOne(s syscall.Handle, rawsa []syscall.RawSockaddrAny, o *operation) (string, error) { // Submit accept request. - o.handle = s o.rsan = int32(unsafe.Sizeof(rawsa[0])) _, err := fd.execIO(o, func(o *operation) error { - return AcceptFunc(fd.Sysfd, o.handle, (*byte)(unsafe.Pointer(&rawsa[0])), 0, uint32(o.rsan), uint32(o.rsan), &o.qty, &o.o) + return AcceptFunc(fd.Sysfd, s, (*byte)(unsafe.Pointer(&rawsa[0])), 0, uint32(o.rsan), uint32(o.rsan), &o.qty, &o.o) }) if err != nil { CloseFunc(s) diff --git a/src/internal/poll/sendfile_windows.go b/src/internal/poll/sendfile_windows.go index d1cc04069b..67e7b2e767 100644 --- a/src/internal/poll/sendfile_windows.go +++ b/src/internal/poll/sendfile_windows.go @@ -63,7 +63,6 @@ func SendFile(fd *FD, src uintptr, size int64) (written int64, err error, handle const maxChunkSizePerCall = int64(0x7fffffff - 1) o := &fd.wop - o.handle = hsrc for size > 0 { chunkSize := maxChunkSizePerCall if chunkSize > size { @@ -76,7 +75,7 @@ func SendFile(fd *FD, src uintptr, size int64) (written int64, err error, handle n, err := fd.execIO(o, func(o *operation) error { o.qty = uint32(chunkSize) - return syscall.TransmitFile(fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND) + return syscall.TransmitFile(fd.Sysfd, hsrc, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND) }) if err != nil { return written, err, written > 0 -- 2.51.0