This adds a `Component` helper type and a `ForEach` helper method.
The first attempt used an interface but interfaces imply allocation. We really
can't afford to allocate here.
This is a huge performance hit. Really, we just need to tell users not to modify
the result.
Also, get rid of an unnecessary pointer indirection (no api change).
This was showing up on CPU profiles as a significant source of repeated
allocations. We don't really care about over allocation (don't keep these slices
around) and should rarely have more than 8 protocols in a single address.
This commit changes the struct to a new Multiaddr interface:
```Go
type Multiaddr interface {
Equal(Multiaddr) bool
Bytes() []byte
String() string
Protocols() []*Protocol
Encapsulate(Multiaddr) Multiaddr
Decapsulate(Multiaddr) Multiaddr
}
```
This means a few things have changed:
- use Multiaddr interface, struct not exported
- Bytes returns a copy of the internal bytes
- Some methods no longer return errors (catch errors in NewMultiaddr)
- String (panics if malformed)
- Protocols (panics if malformed)
- Decapsulate (no-op if not prefix)
- Moved net-specific functions to package
- Multiaddr.DialArgs() -> DialArgs(Multiaddr)
- Multiaddr.IsThinWaist() -> IsThinWaist(Multiaddr)
cc @whyrusleeping @perfmode