Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
nits
  • Loading branch information
MarcoPolo committed Jan 29, 2025
commit f43a27871caa0d4dd6867734d53d6db905141707
6 changes: 0 additions & 6 deletions BREAKING.md

This file was deleted.

8 changes: 2 additions & 6 deletions multiaddr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package multiaddr

import (
"cmp"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -83,12 +84,7 @@ func (m Multiaddr) Compare(o Multiaddr) int {
return cmp
}
}
if len(m) < len(o) {
return -1
} else if len(m) > len(o) {
return 1
}
return 0
return cmp.Compare(len(m), len(o))
}

// Bytes returns the []byte representation of this Multiaddr
Expand Down
5 changes: 5 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func JoinComponents(cs ...Component) Multiaddr {
}

// Join returns a combination of addresses.
// Note: This copies all the components from the input Multiaddrs. Depending on
// your use case, you may prefer to use `append(leftMA, rightMA...)` instead.
func Join(ms ...Multiaddr) Multiaddr {
size := 0
for _, m := range ms {
Expand Down Expand Up @@ -113,6 +115,9 @@ func SplitFunc(m Multiaddr, cb func(Component) bool) (Multiaddr, Multiaddr) {
//
// This function iterates over components.
// Return true to continue iteration, false to stop.
//
// Prefer to use a standard for range loop instead
// e.g. `for _, c := range m { ... }`
func ForEach(m Multiaddr, cb func(c Component) bool) {
for _, c := range m {
if !cb(c) {
Expand Down
15 changes: 15 additions & 0 deletions v015-MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Breaking changes in the large refactor of go-multiaddr v0.15

- There is no `Multiaddr` interface type.
- Multiaddr is now a concrete type. Not an interface.
- Empty Multiaddrs/ should be checked with `.Empty()`, not `== nil`. This is similar to how slices should be checked with `len(s) == 0` rather than `s == nil`.
- Components do not implement `Multiaddr` as there is no `Multiaddr` to implement.
- `Multiaddr` can no longer be a key in a Map. If you want unique Multiaddrs, use `Multiaddr.String()` as the key, otherwise you can use the pointer value `*Multiaddr`.

## Callouts

- Multiaddr.Bytes() is a `O(n)` operation for n Components, as opposed to a `O(1)` operation.

## Migration tips for v0.15

- If trying to encapsulate a Component to a Multiaddr, use `m.encapsulateC(c)`, instead of the old form of `m.Encapsulate(c)`. `Encapsulate` now only accepts a `Multiaddr`. `EncapsulateC` accepts a `Component`.