Commit 067315c6 authored by Dave Cheney's avatar Dave Cheney

net: avoid allocation in setAddr

setAddr was showing up in profiles due to string concatenation construction the os.File name field. netFD.sysfile's Name() is never used, except in dup() so I believe it is safe to avoid this allocation.

R=mikioh.mikioh, rsc
CC=golang-dev
https://golang.org/cl/6742058
parent 542dd8b9
......@@ -312,14 +312,18 @@ func newFD(fd, family, sotype int, net string) (*netFD, error) {
func (fd *netFD) setAddr(laddr, raddr Addr) {
fd.laddr = laddr
fd.raddr = raddr
fd.sysfile = os.NewFile(uintptr(fd.sysfd), fd.net)
}
func (fd *netFD) name() string {
var ls, rs string
if laddr != nil {
ls = laddr.String()
if fd.laddr != nil {
ls = fd.laddr.String()
}
if raddr != nil {
rs = raddr.String()
if fd.raddr != nil {
rs = fd.raddr.String()
}
fd.sysfile = os.NewFile(uintptr(fd.sysfd), fd.net+":"+ls+"->"+rs)
return fd.net + ":" + ls + "->" + rs
}
func (fd *netFD) connect(ra syscall.Sockaddr) error {
......@@ -660,7 +664,7 @@ func (fd *netFD) dup() (f *os.File, err error) {
return nil, &OpError{"setnonblock", fd.net, fd.laddr, err}
}
return os.NewFile(uintptr(ns), fd.sysfile.Name()), nil
return os.NewFile(uintptr(ns), fd.name()), nil
}
func closesocket(s int) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment