mirror of
https://github.com/waku-org/go-multiaddr.git
synced 2025-02-23 03:28:12 +00:00
Merge pull request #56 from multiformats/feat/perf
preallocate protocol slice
This commit is contained in:
commit
f5c34dfc88
11
multiaddr.go
11
multiaddr.go
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user