Commit 6d06d486 authored by Dmitry Vyukov's avatar Dmitry Vyukov

net: don't allocate dialer closure if we won't use it

When we use dialMulti we also allocate dialSingle closure for no reason.

Change-Id: I074282a9d6e2c2a1063ab311a1b95e10fe65219f
Reviewed-on: https://go-review.googlesource.com/4119Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 8ffc4500
......@@ -159,13 +159,15 @@ func (d *Dialer) Dial(network, address string) (Conn, error) {
if err != nil {
return nil, &OpError{Op: "dial", Net: network, Addr: nil, Err: err}
}
dialer := func(deadline time.Time) (Conn, error) {
return dialSingle(network, address, d.LocalAddr, ra.toAddr(), deadline)
}
var dialer func(deadline time.Time) (Conn, error)
if ras, ok := ra.(addrList); ok && d.DualStack && network == "tcp" {
dialer = func(deadline time.Time) (Conn, error) {
return dialMulti(network, address, d.LocalAddr, ras, deadline)
}
} else {
dialer = func(deadline time.Time) (Conn, error) {
return dialSingle(network, address, d.LocalAddr, ra.toAddr(), deadline)
}
}
c, err := dial(network, ra.toAddr(), dialer, d.deadline())
if d.KeepAlive > 0 && err == nil {
......
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