Skip to content

Commit cd771f5

Browse files
committed
fast path for append net.Addr
1 parent f520369 commit cd771f5

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

logger.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,9 +1692,35 @@ func (e *Entry) NetAddr(key string, addr net.Addr) *Entry {
16921692
e.buf = append(e.buf, '"', ':', '"')
16931693
switch v := addr.(type) {
16941694
case *net.TCPAddr:
1695-
e.buf = v.AddrPort().AppendTo(e.buf)
1695+
if len(v.IP) == 4 {
1696+
_ = v.IP[3]
1697+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[0]), 10)
1698+
e.buf = append(e.buf, '.')
1699+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[1]), 10)
1700+
e.buf = append(e.buf, '.')
1701+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[2]), 10)
1702+
e.buf = append(e.buf, '.')
1703+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[3]), 10)
1704+
e.buf = append(e.buf, ':')
1705+
e.buf = strconv.AppendInt(e.buf, int64(v.Port), 10)
1706+
} else {
1707+
e.buf = v.AddrPort().AppendTo(e.buf)
1708+
}
16961709
case *net.UDPAddr:
1697-
e.buf = v.AddrPort().AppendTo(e.buf)
1710+
if len(v.IP) == 4 {
1711+
_ = v.IP[3]
1712+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[0]), 10)
1713+
e.buf = append(e.buf, '.')
1714+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[1]), 10)
1715+
e.buf = append(e.buf, '.')
1716+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[2]), 10)
1717+
e.buf = append(e.buf, '.')
1718+
e.buf = strconv.AppendInt(e.buf, int64(v.IP[3]), 10)
1719+
e.buf = append(e.buf, ':')
1720+
e.buf = strconv.AppendInt(e.buf, int64(v.Port), 10)
1721+
} else {
1722+
e.buf = v.AddrPort().AppendTo(e.buf)
1723+
}
16981724
default:
16991725
e.buf = append(e.buf, addr.String()...)
17001726
}

0 commit comments

Comments
 (0)