mirror of
https://github.com/logos-messaging/go-multiaddr.git
synced 2026-01-05 22:43:10 +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.
|
// 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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user