mirror of
https://github.com/golang/go
synced 2024-11-18 11:44:45 -07:00
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/4119 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
8ffc450049
commit
6d06d4862d
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user