From 7b5f48b227cb6cd1a4096e13d408d8005b15e1c3 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 21 Aug 2023 13:53:04 +0800 Subject: [PATCH] *: use std/slices to replace exp/slices (#46250) ref pingcap/tidb#45933 --- planner/util/BUILD.bazel | 1 - planner/util/path.go | 3 ++- statistics/debugtrace.go | 2 +- statistics/histogram.go | 12 ++++++------ testkit/BUILD.bazel | 1 - testkit/result.go | 13 +++---------- testkit/testutil/BUILD.bazel | 1 - testkit/testutil/handle.go | 2 +- timer/api/BUILD.bazel | 1 - timer/api/mem_store.go | 2 +- 10 files changed, 14 insertions(+), 24 deletions(-) diff --git a/planner/util/BUILD.bazel b/planner/util/BUILD.bazel index 50f4512126508..00fd783b89041 100644 --- a/planner/util/BUILD.bazel +++ b/planner/util/BUILD.bazel @@ -19,7 +19,6 @@ go_library( "//util/collate", "//util/ranger", "//util/size", - "@org_golang_x_exp//slices", ], ) diff --git a/planner/util/path.go b/planner/util/path.go index 68b11bbf5751f..7f959176aef61 100644 --- a/planner/util/path.go +++ b/planner/util/path.go @@ -15,6 +15,8 @@ package util import ( + "slices" + "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/ast" @@ -23,7 +25,6 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/collate" "github.com/pingcap/tidb/util/ranger" - "golang.org/x/exp/slices" ) // AccessPath indicates the way we access a table: by using single index, or by using multiple indexes, diff --git a/statistics/debugtrace.go b/statistics/debugtrace.go index 10d5c52cd2d4b..4bd855a719f3e 100644 --- a/statistics/debugtrace.go +++ b/statistics/debugtrace.go @@ -16,13 +16,13 @@ package statistics import ( "encoding/json" + "slices" "github.com/pingcap/tidb/planner/util/debugtrace" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/ranger" "golang.org/x/exp/maps" - "golang.org/x/exp/slices" ) /* diff --git a/statistics/histogram.go b/statistics/histogram.go index 7b334539414ee..2b757d087f784 100644 --- a/statistics/histogram.go +++ b/statistics/histogram.go @@ -18,6 +18,7 @@ import ( "bytes" "fmt" "math" + "slices" "sort" "strings" "time" @@ -42,7 +43,6 @@ import ( "github.com/pingcap/tipb/go-tipb" "github.com/twmb/murmur3" "go.uber.org/zap" - "golang.org/x/exp/slices" ) // Histogram represents statistics for a column or index. @@ -347,8 +347,8 @@ func (hg *Histogram) RemoveVals(valCntPairs []TopNMeta) { // AddIdxVals adds the given values to the histogram. func (hg *Histogram) AddIdxVals(idxValCntPairs []TopNMeta) { totalAddCnt := int64(0) - slices.SortFunc(idxValCntPairs, func(i, j TopNMeta) bool { - return bytes.Compare(i.Encoded, j.Encoded) < 0 + slices.SortFunc(idxValCntPairs, func(i, j TopNMeta) int { + return bytes.Compare(i.Encoded, j.Encoded) }) for bktIdx, pairIdx := 0, 0; bktIdx < hg.Len(); bktIdx++ { for pairIdx < len(idxValCntPairs) { @@ -1540,19 +1540,19 @@ func MergePartitionHist2GlobalHist(sc *stmtctx.StatementContext, hists []*Histog buckets = buckets[:tail] var sortError error - slices.SortFunc(buckets, func(i, j *bucket4Merging) bool { + slices.SortFunc(buckets, func(i, j *bucket4Merging) int { res, err := i.upper.Compare(sc, j.upper, collate.GetBinaryCollator()) if err != nil { sortError = err } if res != 0 { - return res < 0 + return res } res, err = i.lower.Compare(sc, j.lower, collate.GetBinaryCollator()) if err != nil { sortError = err } - return res < 0 + return res }) if sortError != nil { return nil, sortError diff --git a/testkit/BUILD.bazel b/testkit/BUILD.bazel index de75ed3c996c9..aca65b9c5b78d 100644 --- a/testkit/BUILD.bazel +++ b/testkit/BUILD.bazel @@ -44,7 +44,6 @@ go_library( "@com_github_tikv_client_go_v2//tikv", "@com_github_tikv_client_go_v2//tikvrpc", "@io_opencensus_go//stats/view", - "@org_golang_x_exp//slices", "@org_uber_go_atomic//:atomic", "@org_uber_go_zap//:zap", ], diff --git a/testkit/result.go b/testkit/result.go index 4995a42778b84..417455d3f0988 100644 --- a/testkit/result.go +++ b/testkit/result.go @@ -19,11 +19,11 @@ package testkit import ( "bytes" "fmt" + "slices" "strings" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" ) // Result is the result returned by MustQuery. @@ -86,15 +86,8 @@ func Rows(args ...string) [][]interface{} { // Sort sorts and return the result. func (res *Result) Sort() *Result { - slices.SortFunc(res.rows, func(a, b []string) bool { - for i := range a { - if a[i] < b[i] { - return true - } else if a[i] > b[i] { - return false - } - } - return false + slices.SortFunc(res.rows, func(a, b []string) int { + return slices.Compare(a, b) }) return res } diff --git a/testkit/testutil/BUILD.bazel b/testkit/testutil/BUILD.bazel index 3f4ed7312c01c..25e0a5265f6d4 100644 --- a/testkit/testutil/BUILD.bazel +++ b/testkit/testutil/BUILD.bazel @@ -19,7 +19,6 @@ go_library( "//util/logutil", "@com_github_pingcap_log//:log", "@com_github_stretchr_testify//require", - "@org_golang_x_exp//slices", "@org_uber_go_zap//:zap", "@org_uber_go_zap//zapcore", ], diff --git a/testkit/testutil/handle.go b/testkit/testutil/handle.go index 52161acbd1112..c0832562f8816 100644 --- a/testkit/testutil/handle.go +++ b/testkit/testutil/handle.go @@ -17,6 +17,7 @@ package testutil import ( + "slices" "testing" "github.com/pingcap/tidb/kv" @@ -25,7 +26,6 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/codec" "github.com/stretchr/testify/require" - "golang.org/x/exp/slices" ) // MustNewCommonHandle create a common handle with given values. diff --git a/timer/api/BUILD.bazel b/timer/api/BUILD.bazel index 5419f6d33e3dd..4e42f9168e1a4 100644 --- a/timer/api/BUILD.bazel +++ b/timer/api/BUILD.bazel @@ -18,7 +18,6 @@ go_library( "//util/logutil", "@com_github_google_uuid//:uuid", "@com_github_pingcap_errors//:errors", - "@org_golang_x_exp//slices", "@org_uber_go_zap//:zap", ], ) diff --git a/timer/api/mem_store.go b/timer/api/mem_store.go index 63e16d1639ded..e4e884fc7ea3d 100644 --- a/timer/api/mem_store.go +++ b/timer/api/mem_store.go @@ -17,12 +17,12 @@ package api import ( "context" "encoding/hex" + "slices" "sync" "time" "github.com/google/uuid" "github.com/pingcap/errors" - "golang.org/x/exp/slices" ) type memStoreWatcher struct {