Skip to content

Commit 1d7df48

Browse files
jishudashuv1rtl
authored andcommitted
refactor: use maps.Copy for cleaner map handling (ethersphere#5168)
Signed-off-by: jishudashu <979260390@qq.com>
1 parent a033008 commit 1d7df48

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

pkg/accounting/accounting.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"context"
1111
"errors"
1212
"fmt"
13+
"maps"
1314
"math/big"
1415
"strings"
1516
"sync"
@@ -721,9 +722,7 @@ func (a *Accounting) PeerAccounting() (map[string]PeerInfo, error) {
721722

722723
a.accountingPeersMu.Lock()
723724
accountingPeersList := make(map[string]*accountingPeer)
724-
for peer, accountingPeer := range a.accountingPeers {
725-
accountingPeersList[peer] = accountingPeer
726-
}
725+
maps.Copy(accountingPeersList, a.accountingPeers)
727726
a.accountingPeersMu.Unlock()
728727

729728
for peer, accountingPeer := range accountingPeersList {

pkg/transaction/backendsimulation/backend.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package backendsimulation
77
import (
88
"context"
99
"errors"
10+
"maps"
1011
"math/big"
1112

1213
"github.com/ethereum/go-ethereum"
@@ -74,15 +75,11 @@ func (m *simulatedBackend) advanceBlock() {
7475
m.blockNumber = block.Number
7576

7677
if block.Receipts != nil {
77-
for hash, receipt := range block.Receipts {
78-
m.receipts[hash] = receipt
79-
}
78+
maps.Copy(m.receipts, block.Receipts)
8079
}
8180

8281
if block.NoncesAt != nil {
83-
for addr, nonce := range block.NoncesAt {
84-
m.noncesAt[addr] = nonce
85-
}
82+
maps.Copy(m.noncesAt, block.NoncesAt)
8683
}
8784
}
8885

0 commit comments

Comments
 (0)