optimize: reduce func findProcessName mem allocs and copy

This commit is contained in:
ruokeqx 2024-07-16 20:16:37 +08:00 committed by 世界
parent f06b8db315
commit d91043766a
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -60,12 +60,12 @@ func findProcessName(network string, ip netip.Addr, port int) (string, error) {
isIPv4 := ip.Is4() isIPv4 := ip.Is4()
value, err := syscall.Sysctl(spath) value, err := unix.SysctlRaw(spath)
if err != nil { if err != nil {
return "", err return "", err
} }
buf := []byte(value) buf := value
// from darwin-xnu/bsd/netinet/in_pcblist.c:get_pcblist_n // from darwin-xnu/bsd/netinet/in_pcblist.c:get_pcblist_n
// size/offset are round up (aligned) to 8 bytes in darwin // size/offset are round up (aligned) to 8 bytes in darwin