This commit is contained in:
Josh Bleecher Snyder 2021-07-06 12:26:14 -07:00
parent f27a61502d
commit 961a23b9df
1 changed files with 4 additions and 4 deletions

View File

@ -2861,17 +2861,17 @@ func (c *RebindingUDPConn) ReadFromNetaddr(b []byte) (n int, ipp netaddr.IPPort,
for { for {
pconn := c.currentConn() pconn := c.currentConn()
// Optimization: Treat a few conn types specially. // Optimization: Treat a few pconn types specially.
// *uring.UDPConn can return netaddr.IPPorts directly.
// For *net.UDPConn, ReadFromUDP gets partially inlined, avoiding allocating a *net.UDPAddr, // For *net.UDPConn, ReadFromUDP gets partially inlined, avoiding allocating a *net.UDPAddr,
// as long as pAddr itself doesn't escape. // as long as pAddr itself doesn't escape.
// *uring.UDPConn can return netaddr.IPPorts directly.
// The default case works, but it allocates. // The default case works, but it allocates.
var pAddr *net.UDPAddr var pAddr *net.UDPAddr
switch pconn := pconn.(type) { switch pconn := pconn.(type) {
case *uring.UDPConn:
n, ipp, err = pconn.ReadFromNetaddr(b)
case *net.UDPConn: case *net.UDPConn:
n, pAddr, err = pconn.ReadFromUDP(b) n, pAddr, err = pconn.ReadFromUDP(b)
case *uring.UDPConn:
n, ipp, err = pconn.ReadFromNetaddr(b)
default: default:
var addr net.Addr var addr net.Addr
n, addr, err = pconn.ReadFrom(b) n, addr, err = pconn.ReadFrom(b)