Merge pull request #56 from multiformats/feat/perf

preallocate protocol slice
This commit is contained in:
Jeromy Johnson 2017-09-20 18:40:42 -07:00 committed by GitHub
commit f5c34dfc88

View File

@ -69,16 +69,7 @@ func (m *multiaddr) String() string {
// Protocols returns the list of protocols this Multiaddr has.
// will panic in case we access bytes incorrectly.
func (m *multiaddr) Protocols() []Protocol {
// panic handler, in case we try accessing bytes incorrectly.
defer func() {
if e := recover(); e != nil {
err := e.(error)
panic("Multiaddr.Protocols error: " + err.Error())
}
}()
var ps []Protocol
ps := make([]Protocol, 0, 8)
b := m.bytes
for len(b) > 0 {
code, n, err := ReadVarintCode(b)