Skip to content

Commit

Permalink
Merge pull request #56 from multiformats/feat/perf
Browse files Browse the repository at this point in the history
preallocate protocol slice
  • Loading branch information
whyrusleeping authored Sep 21, 2017
2 parents 6addc7f + d814073 commit f5c34df
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions multiaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f5c34df

Please sign in to comment.