Skip to content

Commit

Permalink
*: use std slices to replace exp/slices (#46020)
Browse files Browse the repository at this point in the history
ref #45933
  • Loading branch information
hawkingrei authored Aug 14, 2023
1 parent d4686cd commit 61ecb59
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 38 deletions.
10 changes: 5 additions & 5 deletions br/pkg/lightning/backend/local/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"sync"
"time"

Expand All @@ -46,7 +47,6 @@ import (
"github.com/tikv/client-go/v2/tikv"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -774,8 +774,8 @@ func (e *Engine) batchIngestSSTs(metas []*sstMeta) error {
if len(metas) == 0 {
return nil
}
slices.SortFunc(metas, func(i, j *sstMeta) bool {
return bytes.Compare(i.minKey, j.minKey) < 0
slices.SortFunc(metas, func(i, j *sstMeta) int {
return bytes.Compare(i.minKey, j.minKey)
})

// non overlapping sst is grouped, and ingested in that order
Expand Down Expand Up @@ -1218,8 +1218,8 @@ func (w *Writer) flushKVs(ctx context.Context) error {
return errors.Trace(err)
}
if !w.isWriteBatchSorted {
slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) bool {
return bytes.Compare(i.Key, j.Key) < 0
slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) int {
return bytes.Compare(i.Key, j.Key)
})
w.isWriteBatchSorted = true
}
Expand Down
1 change: 0 additions & 1 deletion dumpling/export/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ go_library(
"@com_github_spf13_pflag//:pflag",
"@com_github_tikv_pd_client//:client",
"@io_etcd_go_etcd_client_v3//:client",
"@org_golang_x_exp//slices",
"@org_golang_x_sync//errgroup",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_multierr//:multierr",
Expand Down
2 changes: 1 addition & 1 deletion dumpling/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"math/big"
"net"
"slices"
"strconv"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -39,7 +40,6 @@ import (
pd "github.com/tikv/pd/client"
gatomic "go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"golang.org/x/sync/errgroup"
)

Expand Down
2 changes: 1 addition & 1 deletion dumpling/export/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package export
import (
"context"
"database/sql"
"slices"
"strings"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/br/pkg/version"
tcontext "github.com/pingcap/tidb/dumpling/context"
clientv3 "go.etcd.io/etcd/client/v3"
"golang.org/x/exp/slices"
)

const tidbServerInformationPath = "/tidb/server/info"
Expand Down
1 change: 0 additions & 1 deletion expression/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ go_library(
"@com_github_pingcap_tipb//go-tipb",
"@com_github_pkg_errors//:errors",
"@com_github_tikv_client_go_v2//oracle",
"@org_golang_x_exp//slices",
"@org_golang_x_tools//container/intsets",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package expression

import (
"slices"
"strings"
"sync"
"unsafe"
Expand All @@ -42,7 +43,6 @@ import (
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/set"
"github.com/pingcap/tipb/go-tipb"
"golang.org/x/exp/slices"
)

// baseBuiltinFunc will be contained in every struct that implement builtinFunc interface.
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package expression
import (
"context"
"encoding/json"
"slices"
"strings"
"time"

Expand All @@ -37,7 +38,6 @@ import (
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/printer"
"github.com/pingcap/tipb/go-tipb"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_info_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package expression

import (
"slices"
"strings"

"github.com/pingcap/errors"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/printer"
"golang.org/x/exp/slices"
)

func (b *builtinDatabaseSig) vectorized() bool {
Expand Down
7 changes: 4 additions & 3 deletions expression/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package expression

import (
"cmp"
"fmt"
"slices"
"strings"
"unsafe"

Expand All @@ -30,7 +32,6 @@ import (
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/size"
"golang.org/x/exp/slices"
)

// CorrelatedColumn stands for a column in a correlated sub query.
Expand Down Expand Up @@ -735,8 +736,8 @@ func (col *Column) Repertoire() Repertoire {
func SortColumns(cols []*Column) []*Column {
sorted := make([]*Column, len(cols))
copy(sorted, cols)
slices.SortFunc(sorted, func(i, j *Column) bool {
return i.UniqueID < j.UniqueID
slices.SortFunc(sorted, func(i, j *Column) int {
return cmp.Compare(i.UniqueID, j.UniqueID)
})
return sorted
}
Expand Down
2 changes: 1 addition & 1 deletion expression/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package expression
import (
"bytes"
"fmt"
"slices"
"strings"

"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"golang.org/x/exp/slices"
)

// ExplainInfo implements the Expression interface.
Expand Down
1 change: 0 additions & 1 deletion planner/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ go_test(
"@com_github_pingcap_tipb//go-tipb",
"@com_github_prometheus_client_model//go",
"@com_github_stretchr_testify//require",
"@org_golang_x_exp//slices",
"@org_uber_go_goleak//:goleak",
],
)
2 changes: 1 addition & 1 deletion planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"fmt"
"math"
"slices"
"strings"
"unsafe"

Expand Down Expand Up @@ -46,7 +47,6 @@ import (
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

func (p *LogicalUnionScan) exhaustPhysicalPlans(prop *property.PhysicalProperty) ([]PhysicalPlan, bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package core
import (
"fmt"
"math"
"slices"
"strings"

"github.com/pingcap/errors"
Expand All @@ -41,7 +42,6 @@ import (
"github.com/pingcap/tidb/util/set"
"github.com/pingcap/tidb/util/tracing"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const (
Expand Down
7 changes: 4 additions & 3 deletions planner/core/fragment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package core

import (
"cmp"
"context"
"slices"
"sync/atomic"
"time"
"unsafe"
Expand All @@ -37,7 +39,6 @@ import (
"github.com/pingcap/tidb/util/tiflashcompute"
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

// Fragment is cut from the whole pushed-down plan by network communication.
Expand Down Expand Up @@ -598,8 +599,8 @@ func (e *mppTaskGenerator) constructMPPTasksImpl(ctx context.Context, ts *Physic
}

func (e *mppTaskGenerator) constructMPPBuildTaskReqForPartitionedTable(ts *PhysicalTableScan, splitedRanges []*ranger.Range, partitions []table.PhysicalTable) (*kv.MPPBuildTasksRequest, []int64, error) {
slices.SortFunc(partitions, func(i, j table.PhysicalTable) bool {
return i.GetPhysicalID() < j.GetPhysicalID()
slices.SortFunc(partitions, func(i, j table.PhysicalTable) int {
return cmp.Compare(i.GetPhysicalID(), j.GetPhysicalID())
})
partitionIDAndRanges := make([]kv.PartitionIDAndRanges, len(partitions))
allPartitionsIDs := make([]int64, len(partitions))
Expand Down
4 changes: 2 additions & 2 deletions planner/core/hashcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package core
import (
"bytes"
"encoding/binary"
"slices"

"github.com/pingcap/tidb/util/plancodec"
"golang.org/x/exp/slices"
)

func encodeIntAsUint32(result []byte, value int) []byte {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (p *LogicalSelection) HashCode() []byte {
condHashCodes[i] = expr.HashCode(p.SCtx().GetSessionVars().StmtCtx)
}
// Sort the conditions, so `a > 1 and a < 100` can equal to `a < 100 and a > 1`.
slices.SortFunc(condHashCodes, func(i, j []byte) bool { return bytes.Compare(i, j) < 0 })
slices.SortFunc(condHashCodes, func(i, j []byte) int { return bytes.Compare(i, j) })

for _, condHashCode := range condHashCodes {
result = encodeIntAsUint32(result, len(condHashCode))
Expand Down
2 changes: 1 addition & 1 deletion planner/core/memtable_predicate_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"math"
"regexp"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -41,7 +42,6 @@ import (
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

// MemTablePredicateExtractor is used to extract some predicates from `WHERE` clause
Expand Down
2 changes: 1 addition & 1 deletion planner/core/memtable_predicate_extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"regexp"
"slices"
"sort"
"strconv"
"testing"
Expand All @@ -36,7 +37,6 @@ import (
"github.com/pingcap/tidb/util/hint"
"github.com/pingcap/tidb/util/set"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func getLogicalMemTable(t *testing.T, dom *domain.Domain, se session.Session, parser *parser.Parser, sql string) *plannercore.LogicalMemTable {
Expand Down
7 changes: 4 additions & 3 deletions planner/core/plan_cache_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package core

import (
"cmp"
"context"
"math"
"slices"
"strconv"
"time"
"unsafe"
Expand Down Expand Up @@ -44,7 +46,6 @@ import (
utilpc "github.com/pingcap/tidb/util/plancache"
"github.com/pingcap/tidb/util/size"
atomic2 "go.uber.org/atomic"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -109,8 +110,8 @@ func GeneratePlanCacheStmtWithAST(ctx context.Context, sctx sessionctx.Context,
// The parameter markers are appended in visiting order, which may not
// be the same as the position order in the query string. We need to
// sort it by position.
slices.SortFunc(extractor.markers, func(i, j ast.ParamMarkerExpr) bool {
return i.(*driver.ParamMarkerExpr).Offset < j.(*driver.ParamMarkerExpr).Offset
slices.SortFunc(extractor.markers, func(i, j ast.ParamMarkerExpr) int {
return cmp.Compare(i.(*driver.ParamMarkerExpr).Offset, j.(*driver.ParamMarkerExpr).Offset)
})
paramCount := len(extractor.markers)
for i := 0; i < paramCount; i++ {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/rule_join_reorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import (
"bytes"
"context"
"fmt"
"slices"

"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/tracing"
"golang.org/x/exp/slices"
)

// extractJoinGroup extracts all the join nodes connected with continuous
Expand Down
7 changes: 4 additions & 3 deletions planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package core

import (
"bytes"
"cmp"
"context"
"fmt"
gomath "math"
"slices"
"sort"
"strings"

Expand All @@ -37,7 +39,6 @@ import (
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/ranger"
"github.com/pingcap/tidb/util/set"
"golang.org/x/exp/slices"
)

// FullRange represent used all partitions.
Expand Down Expand Up @@ -1973,8 +1974,8 @@ func appendMakeUnionAllChildrenTranceStep(origin *DataSource, usedMap map[int64]
for _, def := range usedMap {
used = append(used, def)
}
slices.SortFunc(used, func(i, j model.PartitionDefinition) bool {
return i.ID < j.ID
slices.SortFunc(used, func(i, j model.PartitionDefinition) int {
return cmp.Compare(i.ID, j.ID)
})
if len(children) == 1 {
newDS := plan.(*DataSource)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/rule_predicate_simplification.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package core
import (
"context"
"errors"
"slices"

"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/sessionctx"
"golang.org/x/exp/slices"
)

// predicateSimplification consolidates different predcicates on a column and its equivalence classes. Initial out is for
Expand Down
Loading

0 comments on commit 61ecb59

Please sign in to comment.