Skip to content

Commit

Permalink
*: use std/slices to replace exp/slices (#46250)
Browse files Browse the repository at this point in the history
ref #45933
  • Loading branch information
hawkingrei authored Aug 21, 2023
1 parent 8c1d2c8 commit 7b5f48b
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 24 deletions.
1 change: 0 additions & 1 deletion planner/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ go_library(
"//util/collate",
"//util/ranger",
"//util/size",
"@org_golang_x_exp//slices",
],
)

Expand Down
3 changes: 2 additions & 1 deletion planner/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package util

import (
"slices"

"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/ast"
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion statistics/debugtrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

/*
Expand Down
12 changes: 6 additions & 6 deletions statistics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"fmt"
"math"
"slices"
"sort"
"strings"
"time"
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion testkit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
13 changes: 3 additions & 10 deletions testkit/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion testkit/testutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
2 changes: 1 addition & 1 deletion testkit/testutil/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package testutil

import (
"slices"
"testing"

"github.com/pingcap/tidb/kv"
Expand All @@ -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.
Expand Down
1 change: 0 additions & 1 deletion timer/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
2 changes: 1 addition & 1 deletion timer/api/mem_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7b5f48b

Please sign in to comment.