libnetwork: Sandbox.resolveName: add fast-path for alias lookups

Skip faster when we're looking for aliases. Also check for the list
of aliases to be empty, not just `nil` (although in practice it should
be equivalent).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-17 12:48:37 +02:00
parent 9249b34be8
commit f549aaa205
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -490,18 +490,17 @@ func (sb *Sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
func (sb *Sandbox) resolveName(nameOrAlias string, networkName string, epList []*Endpoint, lookupAlias bool, ipType int) (_ []net.IP, ipv6Miss bool) {
for _, ep := range epList {
name := nameOrAlias
nw := ep.getNetwork()
if lookupAlias && len(ep.aliases) == 0 {
continue
}
nw := ep.getNetwork()
if networkName != "" && networkName != nw.Name() {
continue
}
name := nameOrAlias
if lookupAlias {
if ep.aliases == nil {
continue
}
var ok bool
ep.mu.Lock()
name, ok = ep.aliases[nameOrAlias]