Skip to content

Commit

Permalink
chore: use slices.Clone to replace CloneSlice (pingcap#57317)
Browse files Browse the repository at this point in the history
  • Loading branch information
YuJuncen authored Nov 12, 2024
1 parent 3578b1d commit f973f19
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
3 changes: 2 additions & 1 deletion br/pkg/streamhelper/advancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"context"
"fmt"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -233,7 +234,7 @@ func (c *CheckpointAdvancer) tryAdvance(ctx context.Context, length int,
defer c.checkpointsMu.Unlock()
c.checkpoints.Merge(spans.Valued{Key: kr, Value: u})
})
clampedRanges := utils.IntersectAll(ranges, utils.CloneSlice(c.taskRange))
clampedRanges := utils.IntersectAll(ranges, slices.Clone(c.taskRange))
for _, r := range clampedRanges {
workers.ApplyOnErrorGroup(eg, func() (e error) {
defer c.recordTimeCost("get regions in range")()
Expand Down
7 changes: 0 additions & 7 deletions br/pkg/utils/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ func clampInOneRange(rng kv.KeyRange, clampIn kv.KeyRange) (kv.KeyRange, failedT
return rng, successClamp
}

// CloneSlice sallowly clones a slice.
func CloneSlice[T any](s []T) []T {
r := make([]T, len(s))
copy(r, s)
return r
}

// IntersectAll returns the intersect of two set of segments.
// OWNERSHIP INFORMATION:
// For running faster, this function would MUTATE the input slice. (i.e. takes its ownership.)
Expand Down
3 changes: 2 additions & 1 deletion br/pkg/utils/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package utils
import (
"encoding/hex"
"fmt"
"slices"
"testing"

"github.com/pingcap/tidb/pkg/kv"
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestClampKeyRanges(t *testing.T) {
run := func(t *testing.T, c Case) {
require.ElementsMatch(
t,
IntersectAll(CloneSlice(c.ranges), CloneSlice(c.clampIn)),
IntersectAll(slices.Clone(c.ranges), slices.Clone(c.clampIn)),
c.result)
require.ElementsMatch(
t,
Expand Down

0 comments on commit f973f19

Please sign in to comment.