Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/mysql: switch to new API for x/exp/slices.SortFunc #13644

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ require (
go.etcd.io/etcd/client/v3 v3.5.8
go.uber.org/mock v0.2.0
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.9.0
golang.org/x/oauth2 v0.7.0
golang.org/x/sys v0.8.0 // indirect
Expand Down Expand Up @@ -106,7 +106,7 @@ require (
github.com/spf13/afero v1.9.3
github.com/spf13/jwalterweatherman v1.1.0
github.com/xlab/treeprint v1.2.0
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
golang.org/x/sync v0.1.0
modernc.org/sqlite v1.20.3
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE=
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY=
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand All @@ -693,8 +693,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
4 changes: 2 additions & 2 deletions go/mysql/collations/uca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,8 @@ func TestUCACollationOrder(t *testing.T) {
j := rand.Intn(i + 1)
ary[i], ary[j] = ary[j], ary[i]
}
slices.SortFunc(ary, func(a, b string) bool {
return col.Collate([]byte(a), []byte(b), false) < 0
slices.SortFunc(ary, func(a, b string) int {
return col.Collate([]byte(a), []byte(b), false)
})
require.Equal(t, sorted, ary)
}
Expand Down
14 changes: 12 additions & 2 deletions go/mysql/json/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,18 @@ func (o *Object) sort() {
return
}

slices.SortStableFunc(o.kvs, func(a, b kv) bool {
return a.k < b.k
slices.SortStableFunc(o.kvs, func(a, b kv) int {
// TODO: switch to cmp.Compare for Go 1.21+.
//
// https://pkg.go.dev/cmp@master#Compare.
switch {
case a.k < b.k:
return -1
case a.k > b.k:
return 1
default:
return 0
}
})
uniq := o.kvs[:1]
for _, kv := range o.kvs[1:] {
Expand Down
18 changes: 14 additions & 4 deletions go/mysql/mysql56_gtid_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,18 @@ func ParseMysql56GTIDSet(s string) (Mysql56GTIDSet, error) {
intervals = append(sidIntervals, intervals...)
}
// Internally we expect intervals to be stored in order.
slices.SortFunc(intervals, func(a, b interval) bool {
return a.start < b.start
slices.SortFunc(intervals, func(a, b interval) int {
// TODO: switch to cmp.Compare for Go 1.21+.
//
// https://pkg.go.dev/cmp@master#Compare.
switch {
case a.start < b.start:
return -1
case a.start > b.start:
return 1
default:
return 0
}
})
set[sid] = intervals
}
Expand All @@ -149,8 +159,8 @@ func (set Mysql56GTIDSet) SIDs() []SID {
}

func sortSIDs(sids []SID) {
slices.SortFunc(sids, func(a, b SID) bool {
return bytes.Compare(a[:], b[:]) < 0
slices.SortFunc(sids, func(a, b SID) int {
return bytes.Compare(a[:], b[:])
})
}

Expand Down