From 674b52c85c25c11b76234dfc105ab307dc673098 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Thu, 27 Jul 2023 09:04:36 -0400 Subject: [PATCH] go/mysql: switch to new API for x/exp/slices.SortFunc Signed-off-by: Matt Layher --- go.mod | 4 ++-- go.sum | 8 ++++---- go/mysql/collations/uca_test.go | 4 ++-- go/mysql/json/parser.go | 14 ++++++++++++-- go/mysql/mysql56_gtid_set.go | 18 ++++++++++++++---- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 0998b825a71..af6767ba7bc 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index 6dd49d77c85..39777e9b54a 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/go/mysql/collations/uca_test.go b/go/mysql/collations/uca_test.go index 5e3f22929c8..34e7015c00f 100644 --- a/go/mysql/collations/uca_test.go +++ b/go/mysql/collations/uca_test.go @@ -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) } diff --git a/go/mysql/json/parser.go b/go/mysql/json/parser.go index c9d71e010a8..aa2e0831df2 100644 --- a/go/mysql/json/parser.go +++ b/go/mysql/json/parser.go @@ -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:] { diff --git a/go/mysql/mysql56_gtid_set.go b/go/mysql/mysql56_gtid_set.go index 63e778f3527..10148f41c90 100644 --- a/go/mysql/mysql56_gtid_set.go +++ b/go/mysql/mysql56_gtid_set.go @@ -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 } @@ -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[:]) }) }