From 2899be812046515c7d9d9d3f925c7bcfca093e8a Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Fri, 17 Jul 2015 10:16:45 +0900 Subject: [PATCH] net: avoid unnecessary conversion in address selection Change-Id: I0d940810b493249bc092cd38bdb434f7fa67cafb Reviewed-on: https://go-review.googlesource.com/12341 Reviewed-by: Brad Fitzpatrick Run-TryBot: Mikio Hara TryBot-Result: Gobot Gobot --- src/net/addrselect.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/net/addrselect.go b/src/net/addrselect.go index 56a618aa267..e7b2b48b463 100644 --- a/src/net/addrselect.go +++ b/src/net/addrselect.go @@ -40,13 +40,16 @@ func sortByRFC6724withSrcs(addrs []IPAddr, srcs []IP) { // number is irrelevant. func srcAddrs(addrs []IPAddr) []IP { srcs := make([]IP, len(addrs)) + dst := UDPAddr{Port: 9} for i := range addrs { - conn, err := Dial("udp", JoinHostPort(addrs[i].IP.String(), "1234")) + dst.IP = addrs[i].IP + dst.Zone = addrs[i].Zone + c, err := DialUDP("udp", nil, &dst) if err == nil { - if ua, ok := conn.LocalAddr().(*UDPAddr); ok { - srcs[i] = ua.IP + if src, ok := c.LocalAddr().(*UDPAddr); ok { + srcs[i] = src.IP } - conn.Close() + c.Close() } } return srcs