Commit f5c34dfc authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #56 from multiformats/feat/perf

preallocate protocol slice
parents 6addc7f5 d8140735
...@@ -69,16 +69,7 @@ func (m *multiaddr) String() string { ...@@ -69,16 +69,7 @@ func (m *multiaddr) String() string {
// Protocols returns the list of protocols this Multiaddr has. // Protocols returns the list of protocols this Multiaddr has.
// will panic in case we access bytes incorrectly. // will panic in case we access bytes incorrectly.
func (m *multiaddr) Protocols() []Protocol { func (m *multiaddr) Protocols() []Protocol {
ps := make([]Protocol, 0, 8)
// 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
b := m.bytes b := m.bytes
for len(b) > 0 { for len(b) > 0 {
code, n, err := ReadVarintCode(b) code, n, err := ReadVarintCode(b)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment