Skip to content

Commit

Permalink
net/netip: remove Prefix.Compare for Go 1.22
Browse files Browse the repository at this point in the history
API questions remain, so we decided to back it out for Go 1.22.
Code still lives in the repo, just unexported.

For #61642.

Change-Id: Iccd91b0da48ae72dec9f660476826a220c7ca4be
Reviewed-on: https://go-review.googlesource.com/c/go/+/549615
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: David Anderson <[email protected]>
Auto-Submit: Russ Cox <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
  • Loading branch information
rsc authored and gopherbot committed Dec 14, 2023
1 parent e44b8b1 commit d73b432
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion api/go1.22.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ pkg net/http, func ServeFileFS(ResponseWriter, *Request, fs.FS, string) #51971
pkg net/http, method (*Request) PathValue(string) string #61410
pkg net/http, method (*Request) SetPathValue(string, string) #61410
pkg net/netip, method (AddrPort) Compare(AddrPort) int #61642
pkg net/netip, method (Prefix) Compare(Prefix) int #61642
pkg os, method (*File) WriteTo(io.Writer) (int64, error) #58808
pkg reflect, func PtrTo //deprecated #59599
pkg reflect, func TypeFor[$0 interface{}]() Type #60088
Expand Down
2 changes: 2 additions & 0 deletions src/net/netip/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ var TestAppendToMarshal = testAppendToMarshal

func (a Addr) IsZero() bool { return a.isZero() }
func (p Prefix) IsZero() bool { return p.isZero() }

func (p Prefix) Compare(p2 Prefix) int { return p.compare(p2) }
7 changes: 5 additions & 2 deletions src/net/netip/netip.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,12 +1261,15 @@ func (p Prefix) isZero() bool { return p == Prefix{} }
// IsSingleIP reports whether p contains exactly one IP.
func (p Prefix) IsSingleIP() bool { return p.IsValid() && p.Bits() == p.ip.BitLen() }

// Compare returns an integer comparing two prefixes.
// compare returns an integer comparing two prefixes.
// The result will be 0 if p == p2, -1 if p < p2, and +1 if p > p2.
// Prefixes sort first by validity (invalid before valid), then
// address family (IPv4 before IPv6), then prefix length, then
// address.
func (p Prefix) Compare(p2 Prefix) int {
//
// Unexported for Go 1.22 because we may want to compare by p.Addr first.
// See post-acceptance discussion on go.dev/issue/61642.
func (p Prefix) compare(p2 Prefix) int {
if c := cmp.Compare(p.Addr().BitLen(), p2.Addr().BitLen()); c != 0 {
return c
}
Expand Down

0 comments on commit d73b432

Please sign in to comment.