preallocate protocol slice

This was showing up on CPU profiles as a significant source of repeated
allocations. We don't really care about over allocation (don't keep these slices
around) and should rarely have more than 8 protocols in a single address.
This commit is contained in:
Steven Allen 2017-09-20 18:17:12 -07:00
parent 6addc7f583
commit 6362ccb0d2

View File

@ -78,7 +78,7 @@ func (m *multiaddr) Protocols() []Protocol {
}
}()
var ps []Protocol
ps := make([]Protocol, 0, 8)
b := m.bytes
for len(b) > 0 {
code, n, err := ReadVarintCode(b)