Skip to content

Commit 483963c

Browse files
committed
run modernize -category=mapsloop -fix -test ./...
1 parent e45399e commit 483963c

File tree

16 files changed

+42
-84
lines changed

16 files changed

+42
-84
lines changed

agreement/fuzzer/ledger_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package fuzzer
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223
"math/rand"
2324

2425
"github.com/algorand/go-algorand/agreement"
@@ -154,9 +155,7 @@ func makeTestLedger(state map[basics.Address]basics.AccountData, sync testLedger
154155

155156
// deep copy of state
156157
l.state = make(map[basics.Address]basics.AccountData)
157-
for k, v := range state {
158-
l.state[k] = v
159-
}
158+
maps.Copy(l.state, state)
160159

161160
l.notifications = make(map[basics.Round]signal)
162161
l.EnsuringDigestStartCh = make(chan struct{})

config/consensus.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package config
1818

1919
import (
20+
"maps"
2021
"time"
2122

2223
"github.com/algorand/go-algorand/config/bounds"
@@ -770,9 +771,7 @@ func (cp ConsensusProtocols) DeepCopy() ConsensusProtocols {
770771
// recreate the ApprovedUpgrades map since we don't want to modify the original one.
771772
if consensusParams.ApprovedUpgrades != nil {
772773
newApprovedUpgrades := make(map[protocol.ConsensusVersion]uint64)
773-
for ver, when := range consensusParams.ApprovedUpgrades {
774-
newApprovedUpgrades[ver] = when
775-
}
774+
maps.Copy(newApprovedUpgrades, consensusParams.ApprovedUpgrades)
776775
consensusParams.ApprovedUpgrades = newApprovedUpgrades
777776
}
778777
staticConsensus[consensusVersion] = consensusParams

crypto/merkletrie/cache.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ func (mtc *merkleTrieCache) loadPage(page uint64) (err error) {
256256
mtc.cachedNodeCount += len(mtc.pageToNIDsPtr[page])
257257
} else {
258258
mtc.cachedNodeCount -= len(mtc.pageToNIDsPtr[page])
259-
for nodeID, pnode := range decodedNodes {
260-
mtc.pageToNIDsPtr[page][nodeID] = pnode
261-
}
259+
maps.Copy(mtc.pageToNIDsPtr[page], decodedNodes)
262260
mtc.cachedNodeCount += len(mtc.pageToNIDsPtr[page])
263261
}
264262

@@ -485,9 +483,7 @@ func (mtc *merkleTrieCache) reallocatePendingPages(stats *CommitStats) (pagesToC
485483
delete(createdPages, page)
486484
}
487485

488-
for pageID, page := range mtc.reallocatedPages {
489-
createdPages[pageID] = page
490-
}
486+
maps.Copy(createdPages, mtc.reallocatedPages)
491487

492488
for _, nodeIDs := range createdPages {
493489
for _, node := range nodeIDs {

data/account/registeryDbOps.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"database/sql"
2222
"errors"
2323
"fmt"
24+
"maps"
2425
"strings"
2526

2627
"github.com/algorand/go-algorand/data/basics"
@@ -257,9 +258,7 @@ func (f *flushOp) apply(db *participationDB) error {
257258
if err != nil {
258259
// put back what we didn't finish with
259260
db.mutex.Lock()
260-
for id, v := range dirty {
261-
db.dirty[id] = v
262-
}
261+
maps.Copy(db.dirty, dirty)
263262
db.mutex.Unlock()
264263
}
265264

data/basics/serr.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package basics
1818

1919
import (
2020
"errors"
21+
"maps"
2122
"strings"
2223

2324
"golang.org/x/exp/slog"
@@ -108,9 +109,7 @@ func Wrap(err error, msg string, field string, pairs ...any) error {
108109
var inner *SError
109110
if ok := errors.As(err, &inner); ok {
110111
attributes := make(map[string]any, len(inner.Attrs))
111-
for key, val := range inner.Attrs {
112-
attributes[key] = val
113-
}
112+
maps.Copy(attributes, inner.Attrs)
114113
serr.Attrs[field+"-attrs"] = attributes
115114
}
116115

data/pools/transactionPool.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package pools
1919
import (
2020
"errors"
2121
"fmt"
22+
"maps"
2223
"sync"
2324
"sync/atomic"
2425
"time"
@@ -268,9 +269,7 @@ func (pool *TransactionPool) rememberCommit(flush bool) {
268269
} else {
269270
pool.pendingTxGroups = append(pool.pendingTxGroups, pool.rememberedTxGroups...)
270271

271-
for txid, txn := range pool.rememberedTxids {
272-
pool.pendingTxids[txid] = txn
273-
}
272+
maps.Copy(pool.pendingTxids, pool.rememberedTxids)
274273
}
275274

276275
pool.rememberedTxGroups = nil

data/transactions/logic/mocktracer/scenarios.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package mocktracer
1919
import (
2020
"encoding/hex"
2121
"fmt"
22+
"maps"
2223
"math"
2324

2425
"github.com/algorand/go-algorand/crypto"
@@ -836,9 +837,7 @@ func MergeStateDeltas(deltas ...ledgercore.StateDelta) ledgercore.StateDelta {
836837
includedTx.Intra += txidBase
837838
result.Txids[txid] = includedTx
838839
}
839-
for lease, round := range delta.Txleases {
840-
result.Txleases[lease] = round
841-
}
840+
maps.Copy(result.Txleases, delta.Txleases)
842841
}
843842
return result
844843
}

ledger/acctdeltas_test.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"encoding/binary"
2424
"errors"
2525
"fmt"
26+
"maps"
2627
"math"
2728
"math/rand"
2829
"os"
@@ -188,9 +189,7 @@ func creatablesFromUpdates(base map[basics.Address]basics.AccountData, updates l
188189

189190
func applyPartialDeltas(base map[basics.Address]basics.AccountData, deltas ledgercore.AccountDeltas) map[basics.Address]basics.AccountData {
190191
result := make(map[basics.Address]basics.AccountData, len(base)+deltas.Len())
191-
for addr, ad := range base {
192-
result[addr] = ad
193-
}
192+
maps.Copy(result, base)
194193

195194
for i := 0; i < deltas.Len(); i++ {
196195
addr, _ := deltas.GetByIdx(i)
@@ -1484,18 +1483,10 @@ func (m mockAccountWriter) clone() (m2 mockAccountWriter) {
14841483
m2.resources = make(map[mockResourcesKey]ledgercore.AccountResource, len(m.resources))
14851484
m2.addresses = make(map[basics.Address]trackerdb.AccountRef, len(m.resources))
14861485
m2.rowids = make(map[trackerdb.AccountRef]basics.Address, len(m.rowids))
1487-
for k, v := range m.accounts {
1488-
m2.accounts[k] = v
1489-
}
1490-
for k, v := range m.resources {
1491-
m2.resources[k] = v
1492-
}
1493-
for k, v := range m.addresses {
1494-
m2.addresses[k] = v
1495-
}
1496-
for k, v := range m.rowids {
1497-
m2.rowids[k] = v
1498-
}
1486+
maps.Copy(m2.accounts, m.accounts)
1487+
maps.Copy(m2.resources, m.resources)
1488+
maps.Copy(m2.addresses, m.addresses)
1489+
maps.Copy(m2.rowids, m.rowids)
14991490
m2.lastAcctRef = m.lastAcctRef
15001491
m2.availAcctRefs = m.availAcctRefs
15011492
return m2

ledger/acctonline_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ledger
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223
"sort"
2324
"strconv"
2425
"testing"
@@ -871,9 +872,7 @@ func TestAcctOnlineCacheDBSync(t *testing.T) {
871872
copyGenesisAccts := func() []map[basics.Address]basics.AccountData {
872873
accounts := []map[basics.Address]basics.AccountData{{}}
873874
accounts[0] = make(map[basics.Address]basics.AccountData, numAccts)
874-
for addr, ad := range genesisAccts[0] {
875-
accounts[0][addr] = ad
876-
}
875+
maps.Copy(accounts[0], genesisAccts[0])
877876
return accounts
878877
}
879878

ledger/acctupdates_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24+
"maps"
2425
"os"
2526
"runtime"
2627
"strings"
@@ -173,9 +174,7 @@ func (ml *mockLedgerForTracker) fork(t testing.TB) *mockLedgerForTracker {
173174
consensusVersion: ml.consensusVersion,
174175
trackers: trackerRegistry{log: dblogger},
175176
}
176-
for k, v := range ml.accts {
177-
newLedgerTracker.accts[k] = v
178-
}
177+
maps.Copy(newLedgerTracker.accts, ml.accts)
179178
copy(newLedgerTracker.blocks, ml.blocks)
180179
copy(newLedgerTracker.deltas, ml.deltas)
181180

0 commit comments

Comments
 (0)