refactor(store): use map.Copy for cleaner map handling (#24076)

Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
This commit is contained in:
healthyyyoung 2025-03-21 06:22:52 +08:00 committed by GitHub
parent 73e2bba699
commit f6fa4f25bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 12 deletions

View File

@ -3,6 +3,7 @@ package cachemulti
import (
"fmt"
"io"
"maps"
dbm "github.com/cosmos/cosmos-db"
@ -94,9 +95,7 @@ func (cms Store) SetTracer(w io.Writer) types.MultiStore {
// necessary between tracing operations. It returns a modified MultiStore.
func (cms Store) SetTracingContext(tc types.TraceContext) types.MultiStore {
if cms.traceContext != nil {
for k, v := range tc {
cms.traceContext[k] = v
}
maps.Copy(cms.traceContext, tc)
} else {
cms.traceContext = tc
}

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"math"
"sort"
"strings"
@ -383,9 +384,7 @@ func (rs *Store) getTracingContext() types.TraceContext {
}
ctx := types.TraceContext{}
for k, v := range rs.traceContext {
ctx[k] = v
}
maps.Copy(ctx, rs.traceContext)
return ctx
}

View File

@ -3,6 +3,7 @@ package types
import (
"fmt"
"io"
"maps"
"slices"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
@ -454,9 +455,7 @@ type TraceContext map[string]interface{}
// Clone clones tc into another instance of TraceContext.
func (tc TraceContext) Clone() TraceContext {
ret := TraceContext{}
for k, v := range tc {
ret[k] = v
}
maps.Copy(ret, tc)
return ret
}
@ -467,9 +466,7 @@ func (tc TraceContext) Merge(newTc TraceContext) TraceContext {
tc = TraceContext{}
}
for k, v := range newTc {
tc[k] = v
}
maps.Copy(tc, newTc)
return tc
}