Skip to content

Commit

Permalink
*: use std/slices to replace exp/slices (#46128)
Browse files Browse the repository at this point in the history
ref #45933
  • Loading branch information
hawkingrei authored Aug 16, 2023
1 parent 2af4b4d commit 95b4dcc
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
5 changes: 3 additions & 2 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package ddl

import (
"bytes"
"cmp"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -61,7 +63,6 @@ import (
"github.com/tikv/client-go/v2/tikv"
kvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -1152,7 +1153,7 @@ func RemoveDependentHiddenColumns(tblInfo *model.TableInfo, idxInfo *model.Index
}
}
// Sort the offset in descending order.
slices.SortFunc(hiddenColOffs, func(a, b int) bool { return a > b })
slices.SortFunc(hiddenColOffs, func(a, b int) int { return cmp.Compare(b, a) })
// Move all the dependent hidden columns to the end.
endOffset := len(tblInfo.Columns) - 1
for _, offset := range hiddenColOffs {
Expand Down
4 changes: 2 additions & 2 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ func (e *TableReaderExecutor) buildResp(ctx context.Context, ranges []*ranger.Ra
if err != nil {
return nil, err
}
kvReq.KeyRanges.SortByFunc(func(i, j kv.KeyRange) bool {
return bytes.Compare(i.StartKey, j.StartKey) < 0
kvReq.KeyRanges.SortByFunc(func(i, j kv.KeyRange) int {
return bytes.Compare(i.StartKey, j.StartKey)
})
e.kvRanges = kvReq.KeyRanges.AppendSelfTo(e.kvRanges)

Expand Down
1 change: 0 additions & 1 deletion kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ go_library(
"@com_github_tikv_client_go_v2//tikvrpc/interceptor",
"@com_github_tikv_client_go_v2//util",
"@com_github_tikv_pd_client//:client",
"@org_golang_x_exp//slices",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
Expand Down
24 changes: 12 additions & 12 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"context"
"crypto/tls"
"slices"
"time"

"github.com/pingcap/errors"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/tikv/client-go/v2/util"
pd "github.com/tikv/pd/client"
"go.uber.org/atomic"
"golang.org/x/exp/slices"
)

// UnCommitIndexKVFlag uses to indicate the index key/value is no need to commit.
Expand Down Expand Up @@ -427,20 +427,20 @@ func (rr *KeyRanges) AppendSelfTo(ranges []KeyRange) []KeyRange {

// SortByFunc sorts each partition's ranges.
// Since the ranges are sorted in most cases, we check it first.
func (rr *KeyRanges) SortByFunc(sortFunc func(i, j KeyRange) bool) {
if !slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) bool {
func (rr *KeyRanges) SortByFunc(sortFunc func(i, j KeyRange) int) {
if !slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) int {
// A simple short-circuit since the empty range actually won't make anything wrong.
if len(i) == 0 || len(j) == 0 {
return true
return -1
}
return sortFunc(i[0], j[0])
}) {
slices.SortFunc(rr.ranges, func(i, j []KeyRange) bool {
slices.SortFunc(rr.ranges, func(i, j []KeyRange) int {
if len(i) == 0 {
return true
return -1
}
if len(j) == 0 {
return false
return 1
}
return sortFunc(i[0], j[0])
})
Expand Down Expand Up @@ -481,19 +481,19 @@ func (rr *KeyRanges) PartitionNum() int {

// IsFullySorted checks whether the ranges are sorted inside partition and each partition is also sorated.
func (rr *KeyRanges) IsFullySorted() bool {
sortedByPartition := slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) bool {
sortedByPartition := slices.IsSortedFunc(rr.ranges, func(i, j []KeyRange) int {
// A simple short-circuit since the empty range actually won't make anything wrong.
if len(i) == 0 || len(j) == 0 {
return true
return -1
}
return bytes.Compare(i[0].StartKey, j[0].StartKey) < 0
return bytes.Compare(i[0].StartKey, j[0].StartKey)
})
if !sortedByPartition {
return false
}
for _, ranges := range rr.ranges {
if !slices.IsSortedFunc(ranges, func(i, j KeyRange) bool {
return bytes.Compare(i.StartKey, j.StartKey) < 0
if !slices.IsSortedFunc(ranges, func(i, j KeyRange) int {
return bytes.Compare(i.StartKey, j.StartKey)
}) {
return false
}
Expand Down
1 change: 0 additions & 1 deletion store/mockstore/unistore/util/lockwaiter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ go_library(
"//store/mockstore/unistore/config",
"@com_github_pingcap_kvproto//pkg/deadlock",
"@com_github_pingcap_log//:log",
"@org_golang_x_exp//slices",
"@org_uber_go_zap//:zap",
],
)
Expand Down
7 changes: 4 additions & 3 deletions store/mockstore/unistore/util/lockwaiter/lockwaiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
package lockwaiter

import (
"cmp"
"slices"
"sync"
"time"

"github.com/pingcap/kvproto/pkg/deadlock"
"github.com/pingcap/log"
"github.com/pingcap/tidb/store/mockstore/unistore/config"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

// LockNoWait is used for pessimistic lock wait time
Expand Down Expand Up @@ -51,8 +52,8 @@ type queue struct {

func (q *queue) getOldestWaiter() (*Waiter, []*Waiter) {
// make the waiters in start ts order
slices.SortFunc(q.waiters, func(i, j *Waiter) bool {
return i.startTS < j.startTS
slices.SortFunc(q.waiters, func(i, j *Waiter) int {
return cmp.Compare(i.startTS, j.startTS)
})
oldestWaiter := q.waiters[0]
remainWaiter := q.waiters[1:]
Expand Down
1 change: 0 additions & 1 deletion ttl/ttlworker/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ go_library(
"@com_github_tikv_client_go_v2//tikvrpc",
"@io_etcd_go_etcd_client_v3//:client",
"@org_golang_x_exp//maps",
"@org_golang_x_exp//slices",
"@org_golang_x_time//rate",
"@org_uber_go_multierr//:multierr",
"@org_uber_go_zap//:zap",
Expand Down
2 changes: 1 addition & 1 deletion ttl/ttlworker/timer_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"time"

"github.com/pingcap/errors"
Expand All @@ -30,7 +31,6 @@ import (
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

const (
Expand Down

0 comments on commit 95b4dcc

Please sign in to comment.