diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-04 19:07:22 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-09-07 04:46:25 +0000 |
| commit | ca264cdc6247141a1e042f38c83fff4783f03324 (patch) | |
| tree | 977e7586dedc8e03f11d77780c3cf63497a733d7 /src/internal/syscall | |
| parent | 238274df4eee1752f51b288a11eddaf5365123bf (diff) | |
| download | go-ca264cdc6247141a1e042f38c83fff4783f03324.tar.xz | |
syscall: avoid convT2I allocs for common Windows error values
This is was already done for Unix in https://golang.org/cl/6701 +
https://golang.org/cl/8192. Do it for Windows also.
Fixes #16988
Change-Id: Ia7832b0d0d48566b0cd205652b85130df529592e
Reviewed-on: https://go-review.googlesource.com/28484
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'src/internal/syscall')
| -rw-r--r-- | src/internal/syscall/windows/registry/zsyscall_windows.go | 27 | ||||
| -rw-r--r-- | src/internal/syscall/windows/zsyscall_windows.go | 31 |
2 files changed, 54 insertions, 4 deletions
diff --git a/src/internal/syscall/windows/registry/zsyscall_windows.go b/src/internal/syscall/windows/registry/zsyscall_windows.go index 62affc0b50..36ae303aa5 100644 --- a/src/internal/syscall/windows/registry/zsyscall_windows.go +++ b/src/internal/syscall/windows/registry/zsyscall_windows.go @@ -10,6 +10,31 @@ import ( var _ unsafe.Pointer +// Do the interface allocations only once for common +// Errno values. +const ( + errnoWSAEINPROGRESS = 10036 +) + +var ( + errWSAEINPROGRESS error = syscall.Errno(errnoWSAEINPROGRESS) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoWSAEINPROGRESS: + return errWSAEINPROGRESS + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + var ( modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll")) modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll")) @@ -76,7 +101,7 @@ func expandEnvironmentStrings(src *uint16, dst *uint16, size uint32) (n uint32, n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } diff --git a/src/internal/syscall/windows/zsyscall_windows.go b/src/internal/syscall/windows/zsyscall_windows.go index 6929acfa72..21fe12fe1b 100644 --- a/src/internal/syscall/windows/zsyscall_windows.go +++ b/src/internal/syscall/windows/zsyscall_windows.go @@ -10,6 +10,31 @@ import ( var _ unsafe.Pointer +// Do the interface allocations only once for common +// Errno values. +const ( + errnoWSAEINPROGRESS = 10036 +) + +var ( + errWSAEINPROGRESS error = syscall.Errno(errnoWSAEINPROGRESS) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoWSAEINPROGRESS: + return errWSAEINPROGRESS + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + var ( modiphlpapi = syscall.NewLazyDLL(sysdll.Add("iphlpapi.dll")) modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll")) @@ -33,7 +58,7 @@ func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -45,7 +70,7 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags)) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -64,7 +89,7 @@ func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, nwrite = int32(r0) if nwrite == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } |
