Skip to content

Commit 0d7ee0e

Browse files
rscezz-no
authored andcommitted
net/netip: remove Prefix.Compare for Go 1.22
API questions remain, so we decided to back it out for Go 1.22. Code still lives in the repo, just unexported. For golang#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]>
1 parent de46bc6 commit 0d7ee0e

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

api/go1.22.txt

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pkg net/http, func ServeFileFS(ResponseWriter, *Request, fs.FS, string) #51971
131131
pkg net/http, method (*Request) PathValue(string) string #61410
132132
pkg net/http, method (*Request) SetPathValue(string, string) #61410
133133
pkg net/netip, method (AddrPort) Compare(AddrPort) int #61642
134-
pkg net/netip, method (Prefix) Compare(Prefix) int #61642
135134
pkg os, method (*File) WriteTo(io.Writer) (int64, error) #58808
136135
pkg reflect, func PtrTo //deprecated #59599
137136
pkg reflect, func TypeFor[$0 interface{}]() Type #60088

src/net/netip/export_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ var TestAppendToMarshal = testAppendToMarshal
2828

2929
func (a Addr) IsZero() bool { return a.isZero() }
3030
func (p Prefix) IsZero() bool { return p.isZero() }
31+
32+
func (p Prefix) Compare(p2 Prefix) int { return p.compare(p2) }

src/net/netip/netip.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1261,12 +1261,15 @@ func (p Prefix) isZero() bool { return p == Prefix{} }
12611261
// IsSingleIP reports whether p contains exactly one IP.
12621262
func (p Prefix) IsSingleIP() bool { return p.IsValid() && p.Bits() == p.ip.BitLen() }
12631263

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

0 commit comments

Comments
 (0)