Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: replace maps.Copy which is for map clone with std maps.Clone #55530

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lightning/pkg/importer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ go_library(
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//status",
"@org_golang_x_exp//maps",
"@org_golang_x_sync//errgroup",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_multierr//:multierr",
Expand Down
2 changes: 1 addition & 1 deletion lightning/pkg/importer/get_pre_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"database/sql"
"fmt"
"io"
"maps"
"strings"

mysql_sql_driver "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -52,7 +53,6 @@ import (
"github.com/pingcap/tidb/pkg/util/mock"
pdhttp "github.com/tikv/pd/client/http"
"go.uber.org/zap"
"golang.org/x/exp/maps"
)

// compressionRatio is the tikv/tiflash's compression ratio
Expand Down
1 change: 0 additions & 1 deletion pkg/distsql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ go_library(
"@com_github_tikv_client_go_v2//tikvrpc/interceptor",
"@com_github_tikv_client_go_v2//util",
"@org_golang_google_grpc//metadata",
"@org_golang_x_exp//maps",
"@org_uber_go_zap//:zap",
],
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"container/heap"
"context"
"fmt"
"maps"
"strconv"
"sync/atomic"
"time"
Expand Down Expand Up @@ -46,7 +47,6 @@ import (
"github.com/tikv/client-go/v2/tikv"
clientutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"golang.org/x/exp/maps"
)

var (
Expand Down
4 changes: 1 addition & 3 deletions pkg/domain/sysvar_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ func (do *Domain) GetSessionCache() (map[string]string, error) {
do.sysVarCache.RLock()
defer do.sysVarCache.RUnlock()
// Perform a deep copy since this will be assigned directly to the session
newMap := make(map[string]string, len(do.sysVarCache.session))
maps.Copy(newMap, do.sysVarCache.session)
return newMap, nil
return maps.Clone(do.sysVarCache.session), nil
}

// GetGlobalVar gets an individual global var from the sysvar cache.
Expand Down
16 changes: 4 additions & 12 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"maps"
"math"
"math/rand"
"net"
Expand Down Expand Up @@ -70,7 +71,6 @@ import (
"github.com/tikv/client-go/v2/tikv"
"github.com/twmb/murmur3"
atomic2 "go.uber.org/atomic"
"golang.org/x/exp/maps"
)

var (
Expand Down Expand Up @@ -462,16 +462,10 @@ func (tc *TransactionContext) GetCurrentSavepoint() TxnCtxNeedToRestore {
for k, v := range tc.TableDeltaMap {
tableDeltaMap[k] = v.Clone()
}
pessimisticLockCache := make(map[string][]byte, len(tc.pessimisticLockCache))
maps.Copy(pessimisticLockCache, tc.pessimisticLockCache)
CurrentStmtPessimisticLockCache := make(map[string][]byte, len(tc.CurrentStmtPessimisticLockCache))
maps.Copy(CurrentStmtPessimisticLockCache, tc.CurrentStmtPessimisticLockCache)
Comment on lines -467 to -468
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is useless code, see #43530 (comment)

cachedTables := make(map[int64]any, len(tc.CachedTables))
maps.Copy(cachedTables, tc.CachedTables)
return TxnCtxNeedToRestore{
TableDeltaMap: tableDeltaMap,
pessimisticLockCache: pessimisticLockCache,
CachedTables: cachedTables,
pessimisticLockCache: maps.Clone(tc.pessimisticLockCache),
CachedTables: maps.Clone(tc.CachedTables),
InsertTTLRowsCount: tc.InsertTTLRowsCount,
}
}
Expand Down Expand Up @@ -2878,12 +2872,10 @@ type TableDelta struct {

// Clone returns a cloned TableDelta.
func (td TableDelta) Clone() TableDelta {
colSize := make(map[int64]int64, len(td.ColSize))
maps.Copy(colSize, td.ColSize)
return TableDelta{
Delta: td.Delta,
Count: td.Count,
ColSize: colSize,
ColSize: maps.Clone(td.ColSize),
InitTime: td.InitTime,
TableID: td.TableID,
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package statistics
import (
"cmp"
"fmt"
stdmaps "maps"
"slices"
"strings"

Expand Down Expand Up @@ -169,10 +170,10 @@ func (m *ColAndIdxExistenceMap) IsEmpty() bool {
// Clone deeply copies the map.
func (m *ColAndIdxExistenceMap) Clone() *ColAndIdxExistenceMap {
mm := NewColAndIndexExistenceMap(len(m.colInfoMap), len(m.idxInfoMap))
mm.colInfoMap = maps.Clone(m.colInfoMap)
mm.colAnalyzed = maps.Clone(m.colAnalyzed)
mm.idxAnalyzed = maps.Clone(m.idxAnalyzed)
mm.idxInfoMap = maps.Clone(m.idxInfoMap)
mm.colInfoMap = stdmaps.Clone(m.colInfoMap)
mm.colAnalyzed = stdmaps.Clone(m.colAnalyzed)
mm.idxAnalyzed = stdmaps.Clone(m.idxAnalyzed)
mm.idxInfoMap = stdmaps.Clone(m.idxInfoMap)
return mm
}

Expand Down
1 change: 0 additions & 1 deletion pkg/util/intset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ go_test(
shard_count = 5,
deps = [
"@com_github_stretchr_testify//require",
"@org_golang_x_exp//maps",
"@org_golang_x_tools//container/intsets",
],
)
9 changes: 2 additions & 7 deletions pkg/util/intset/fast_int_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package intset

import (
"fmt"
"maps"
"math/rand"
"reflect"
"runtime"
Expand All @@ -25,7 +26,6 @@ import (
"time"

"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
"golang.org/x/tools/container/intsets"
)

Expand Down Expand Up @@ -95,8 +95,7 @@ func (is IntSet) Equals(target IntSet) bool {
}

func (is *IntSet) CopyFrom(target IntSet) {
*is = NewIntSetWithCap(len(target))
maps.Copy(*is, target)
*is = maps.Clone(target)
}

func (is IntSet) SortedArray() []int {
Expand All @@ -116,10 +115,6 @@ func NewIntSet() IntSet {
return make(map[int]struct{})
}

func NewIntSetWithCap(c int) IntSet {
return make(map[int]struct{}, c)
}

func TestFastIntSetBasic(t *testing.T) {
// Test Insert, Remove, Len, Has.
fis := FastIntSet{}
Expand Down
1 change: 0 additions & 1 deletion pkg/util/stmtsummary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ go_library(
"//pkg/util/set",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_tikv_client_go_v2//util",
"@org_golang_x_exp//maps",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
Expand Down
5 changes: 2 additions & 3 deletions pkg/util/stmtsummary/statement_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"cmp"
"container/list"
"fmt"
"maps"
"math"
"slices"
"strconv"
Expand All @@ -36,7 +37,6 @@ import (
"github.com/pingcap/tidb/pkg/util/plancodec"
"github.com/tikv/client-go/v2/util"
atomic2 "go.uber.org/atomic"
"golang.org/x/exp/maps"
)

// stmtSummaryByDigestKey defines key for stmtSummaryByDigestMap.summaryMap.
Expand Down Expand Up @@ -421,9 +421,8 @@ func (ssMap *stmtSummaryByDigestMap) GetMoreThanCntBindableStmt(cnt int64) []*Bi
PlanHint: ssElement.planHint,
Charset: ssElement.charset,
Collation: ssElement.collation,
Users: make(map[string]struct{}),
Users: maps.Clone(ssElement.authUsers),
}
maps.Copy(stmt.Users, ssElement.authUsers)
// If it is SQL command prepare / execute, the ssElement.sampleSQL is `execute ...`, we should get the original select query.
// If it is binary protocol prepare / execute, ssbd.normalizedSQL should be same as ssElement.sampleSQL.
if ssElement.prepared {
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/stmtsummary/v2/stmtsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,8 @@ func (s *StmtSummary) GetMoreThanCntBindableStmt(cnt int64) []*stmtsummary.Binda
PlanHint: record.PlanHint,
Charset: record.Charset,
Collation: record.Collation,
Users: make(map[string]struct{}),
Users: maps.Clone(record.AuthUsers),
}
maps.Copy(stmt.Users, record.AuthUsers)

// If it is SQL command prepare / execute, the ssElement.sampleSQL
// is `execute ...`, we should get the original select query.
Expand Down