diff --git a/action/protocol/execution/evm/access_list.go b/action/protocol/execution/evm/access_list.go index c6f34e1ec4..406d5d5617 100644 --- a/action/protocol/execution/evm/access_list.go +++ b/action/protocol/execution/evm/access_list.go @@ -6,6 +6,8 @@ package evm import ( + "maps" + "github.com/ethereum/go-ethereum/common" ) @@ -46,9 +48,7 @@ func newAccessList() *accessList { // Copy creates an independent copy of an accessList. func (al *accessList) Copy() *accessList { cp := newAccessList() - for k, v := range al.addresses { - cp.addresses[k] = v - } + maps.Copy(cp.addresses, al.addresses) cp.slots = make([]map[common.Hash]struct{}, len(al.slots)) for i, slotMap := range al.slots { newSlotmap := make(map[common.Hash]struct{}, len(slotMap)) diff --git a/action/protocol/execution/evm/evmstatedbadapter.go b/action/protocol/execution/evm/evmstatedbadapter.go index d19897a9f5..52991f4984 100644 --- a/action/protocol/execution/evm/evmstatedbadapter.go +++ b/action/protocol/execution/evm/evmstatedbadapter.go @@ -10,6 +10,7 @@ import ( "context" "encoding/hex" "fmt" + "maps" "math/big" "sort" @@ -800,9 +801,7 @@ func (stateDB *StateDBAdapter) Snapshot() int { } // save a copy of current SelfDestruct accounts sa := make(deleteAccount) - for k, v := range stateDB.selfDestructed { - sa[k] = v - } + maps.Copy(sa, stateDB.selfDestructed) stateDB.selfDestructedSnapshot[sn] = sa if !stateDB.fixSnapshotOrder { for _, addr := range stateDB.cachedContractAddrs() { @@ -812,9 +811,7 @@ func (stateDB *StateDBAdapter) Snapshot() int { stateDB.contractSnapshot[sn] = c // save a copy of preimages p := make(preimageMap) - for k, v := range stateDB.preimages { - p[k] = v - } + maps.Copy(p, stateDB.preimages) stateDB.preimageSnapshot[sn] = p // save a copy of access list stateDB.accessListSnapshot[sn] = stateDB.accessList.Copy() @@ -823,9 +820,7 @@ func (stateDB *StateDBAdapter) Snapshot() int { stateDB.transientStorageSnapshot[sn] = stateDB.transientStorage.Copy() // save a copy of created account map ca := make(createdAccount) - for k, v := range stateDB.createdAccount { - ca[k] = v - } + maps.Copy(ca, stateDB.createdAccount) stateDB.createdAccountSnapshot[sn] = ca } return sn diff --git a/blockindex/contractstaking/cache.go b/blockindex/contractstaking/cache.go index d1edaaa4ad..27f0eb4473 100644 --- a/blockindex/contractstaking/cache.go +++ b/blockindex/contractstaking/cache.go @@ -8,6 +8,7 @@ package contractstaking import ( "context" "log" + "maps" "math/big" "sync" @@ -289,9 +290,7 @@ func (s *contractStakingCache) Clone() stakingCache { c.candidateBucketMap = make(map[string]map[uint64]bool, len(s.candidateBucketMap)) for k, v := range s.candidateBucketMap { c.candidateBucketMap[k] = make(map[uint64]bool, len(v)) - for k1, v1 := range v { - c.candidateBucketMap[k][k1] = v1 - } + maps.Copy(c.candidateBucketMap[k], v) } c.bucketTypeMap = make(map[uint64]*BucketType, len(s.bucketTypeMap)) for k, v := range s.bucketTypeMap { @@ -300,9 +299,7 @@ func (s *contractStakingCache) Clone() stakingCache { c.propertyBucketTypeMap = make(map[int64]map[uint64]uint64, len(s.propertyBucketTypeMap)) for k, v := range s.propertyBucketTypeMap { c.propertyBucketTypeMap[k] = make(map[uint64]uint64, len(v)) - for k1, v1 := range v { - c.propertyBucketTypeMap[k][k1] = v1 - } + maps.Copy(c.propertyBucketTypeMap[k], v) } c.deltaBucketTypes = make(map[uint64]*BucketType, len(s.deltaBucketTypes)) for k, v := range s.deltaBucketTypes { diff --git a/blockindex/contractstaking/wrappedcache.go b/blockindex/contractstaking/wrappedcache.go index 8e33bd0e1e..8acd4e7c89 100644 --- a/blockindex/contractstaking/wrappedcache.go +++ b/blockindex/contractstaking/wrappedcache.go @@ -7,6 +7,7 @@ package contractstaking import ( "context" + "maps" "math/big" "sort" "sync" @@ -271,9 +272,7 @@ func (wc *wrappedCache) Clone() stakingCache { updatedCandidates := make(map[string]map[uint64]bool, len(wc.updatedCandidates)) for delegate, buckets := range wc.updatedCandidates { updatedBuckets := make(map[uint64]bool, len(buckets)) - for id, updated := range buckets { - updatedBuckets[id] = updated - } + maps.Copy(updatedBuckets, buckets) updatedCandidates[delegate] = updatedBuckets } return &wrappedCache{ diff --git a/dispatcher/dispatcher.go b/dispatcher/dispatcher.go index 67ee89fc74..37300956a4 100644 --- a/dispatcher/dispatcher.go +++ b/dispatcher/dispatcher.go @@ -7,6 +7,7 @@ package dispatcher import ( "context" + "maps" "sync" "time" @@ -186,9 +187,7 @@ func (d *IotxDispatcher) EventAudit() map[iotexrpc.MessageType]int { d.eventAuditLock.RLock() defer d.eventAuditLock.RUnlock() snapshot := make(map[iotexrpc.MessageType]int) - for k, v := range d.eventAudit { - snapshot[k] = v - } + maps.Copy(snapshot, d.eventAudit) return snapshot }