|
93 | 93 |
|
94 | 94 | func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error) {
|
95 | 95 | e, err := netip.ParseAddrPort(s)
|
96 |
| - return asEndpoint(e), err |
| 96 | + if err != nil { |
| 97 | + return nil, err |
| 98 | + } |
| 99 | + return &StdNetEndpoint{ |
| 100 | + AddrPort: e, |
| 101 | + }, nil |
97 | 102 | }
|
98 | 103 |
|
99 | 104 | func (e *StdNetEndpoint) ClearSrc() {
|
@@ -228,7 +233,7 @@ func (s *StdNetBind) makeReceiveIPv4(pc *ipv4.PacketConn, conn *net.UDPConn) Rec
|
228 | 233 | msg := &(*msgs)[i]
|
229 | 234 | sizes[i] = msg.N
|
230 | 235 | addrPort := msg.Addr.(*net.UDPAddr).AddrPort()
|
231 |
| - ep := asEndpoint(addrPort) |
| 236 | + ep := &StdNetEndpoint{AddrPort: addrPort} // TODO: remove allocation |
232 | 237 | getSrcFromControl(msg.OOB[:msg.NN], ep)
|
233 | 238 | eps[i] = ep
|
234 | 239 | }
|
@@ -261,7 +266,7 @@ func (s *StdNetBind) makeReceiveIPv6(pc *ipv6.PacketConn, conn *net.UDPConn) Rec
|
261 | 266 | msg := &(*msgs)[i]
|
262 | 267 | sizes[i] = msg.N
|
263 | 268 | addrPort := msg.Addr.(*net.UDPAddr).AddrPort()
|
264 |
| - ep := asEndpoint(addrPort) |
| 269 | + ep := &StdNetEndpoint{AddrPort: addrPort} // TODO: remove allocation |
265 | 270 | getSrcFromControl(msg.OOB[:msg.NN], ep)
|
266 | 271 | eps[i] = ep
|
267 | 272 | }
|
@@ -408,24 +413,3 @@ func (s *StdNetBind) send6(conn *net.UDPConn, pc *ipv6.PacketConn, ep Endpoint,
|
408 | 413 | s.ipv6MsgsPool.Put(msgs)
|
409 | 414 | return err
|
410 | 415 | }
|
411 |
| - |
412 |
| -// endpointPool contains a re-usable set of mapping from netip.AddrPort to Endpoint. |
413 |
| -// This exists to reduce allocations: Putting a netip.AddrPort in an Endpoint allocates, |
414 |
| -// but Endpoints are immutable, so we can re-use them. |
415 |
| -var endpointPool = sync.Pool{ |
416 |
| - New: func() any { |
417 |
| - return make(map[netip.AddrPort]*StdNetEndpoint) |
418 |
| - }, |
419 |
| -} |
420 |
| - |
421 |
| -// asEndpoint returns an Endpoint containing ap. |
422 |
| -func asEndpoint(ap netip.AddrPort) *StdNetEndpoint { |
423 |
| - m := endpointPool.Get().(map[netip.AddrPort]*StdNetEndpoint) |
424 |
| - defer endpointPool.Put(m) |
425 |
| - e, ok := m[ap] |
426 |
| - if !ok { |
427 |
| - e = &StdNetEndpoint{AddrPort: ap} |
428 |
| - m[ap] = e |
429 |
| - } |
430 |
| - return e |
431 |
| -} |
0 commit comments