Skip to content

Commit

Permalink
*: use std/slices to replace exp/slices (#46107)
Browse files Browse the repository at this point in the history
close #45933
  • Loading branch information
hawkingrei authored Aug 15, 2023
1 parent 6fd1924 commit 04f96b5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion types/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ go_library(
"//util/stringutil",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_log//:log",
"@org_golang_x_exp//slices",
"@org_uber_go_zap//:zap",
],
)
Expand Down
7 changes: 4 additions & 3 deletions types/json_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package types

import (
"bytes"
"cmp"
"encoding/base64"
"encoding/binary"
"encoding/json"
"fmt"
"math"
"reflect"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -33,7 +35,6 @@ import (
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

/*
Expand Down Expand Up @@ -835,8 +836,8 @@ func appendBinaryObject(buf []byte, x map[string]interface{}) ([]byte, error) {
for key, val := range x {
fields = append(fields, field{key: key, val: val})
}
slices.SortFunc(fields, func(i, j field) bool {
return i.key < j.key
slices.SortFunc(fields, func(i, j field) int {
return cmp.Compare(i.key, j.key)
})
for i, field := range fields {
keyEntryOff := keyEntryBegin + i*keyEntrySize
Expand Down
10 changes: 3 additions & 7 deletions types/json_binary_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"encoding/hex"
"fmt"
"math"
"slices"
"sort"
"unicode/utf8"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/stringutil"
"golang.org/x/exp/slices"
)

// Type returns type of BinaryJSON as string.
Expand Down Expand Up @@ -933,9 +933,7 @@ func mergePatchBinaryJSON(target, patch *BinaryJSON) (result *BinaryJSON, err er
for key := range keyValMap {
keys = append(keys, []byte(key))
}
slices.SortFunc(keys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
})
slices.SortFunc(keys, bytes.Compare)
length = len(keys)
values := make([]BinaryJSON, 0, len(keys))
for i := 0; i < length; i++ {
Expand Down Expand Up @@ -1016,9 +1014,7 @@ func mergeBinaryObject(objects []BinaryJSON) BinaryJSON {
}
}
}
slices.SortFunc(keys, func(i, j []byte) bool {
return bytes.Compare(i, j) < 0
})
slices.SortFunc(keys, bytes.Compare)
values := make([]BinaryJSON, len(keys))
for i, key := range keys {
values[i] = keyValMap[string(key)]
Expand Down

0 comments on commit 04f96b5

Please sign in to comment.