all: replace manual map copying with maps.Copy for improved readability
This commit is contained in:
parent
31c972febf
commit
b2e0fdad7b
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"maps"
|
||||
)
|
||||
|
||||
type crawler struct {
|
||||
|
@ -72,9 +73,7 @@ func newCrawler(input nodeSet, bootnodes []*enode.Node, disc resolver, iters ...
|
|||
c.iters = append(c.iters, c.inputIter)
|
||||
// Copy input to output initially. Any nodes that fail validation
|
||||
// will be dropped from output during the run.
|
||||
for id, n := range input {
|
||||
c.output[id] = n
|
||||
}
|
||||
maps.Copy(c.output, input)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"maps"
|
||||
)
|
||||
|
||||
// API is a user facing RPC API to allow controlling the signer and voting
|
||||
|
@ -99,9 +100,7 @@ func (api *API) Proposals() map[common.Address]bool {
|
|||
defer api.clique.lock.RUnlock()
|
||||
|
||||
proposals := make(map[common.Address]bool)
|
||||
for address, auth := range api.clique.proposals {
|
||||
proposals[address] = auth
|
||||
}
|
||||
maps.Copy(proposals, api.clique.proposals)
|
||||
return proposals
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/holiman/uint256"
|
||||
"maps"
|
||||
)
|
||||
|
||||
// So we can deterministically seed different blockchains
|
||||
|
@ -3062,9 +3063,7 @@ func testDeleteRecreateSlotsAcrossManyBlocks(t *testing.T, scheme string) {
|
|||
var exp = new(expectation)
|
||||
exp.blocknum = i + 1
|
||||
exp.values = make(map[int]int)
|
||||
for k, v := range current.values {
|
||||
exp.values[k] = v
|
||||
}
|
||||
maps.Copy(exp.values, current.values)
|
||||
exp.exist = current.exist
|
||||
|
||||
b.SetCoinbase(common.Address{1})
|
||||
|
|
|
@ -388,9 +388,7 @@ func (dl *diffLayer) flatten() snapshot {
|
|||
if parent.stale.Swap(true) {
|
||||
panic("parent diff layer is stale") // we've flattened into the same parent from two children, boo
|
||||
}
|
||||
for hash, data := range dl.accountData {
|
||||
parent.accountData[hash] = data
|
||||
}
|
||||
maps.Copy(parent.accountData, dl.accountData)
|
||||
// Overwrite all the updated storage slots (individually)
|
||||
for accountHash, storage := range dl.storageData {
|
||||
// If storage didn't exist (or was deleted) in the parent, overwrite blindly
|
||||
|
|
|
@ -26,13 +26,12 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb/memorydb"
|
||||
"maps"
|
||||
)
|
||||
|
||||
func copyAccounts(accounts map[common.Hash][]byte) map[common.Hash][]byte {
|
||||
copy := make(map[common.Hash][]byte)
|
||||
for hash, blob := range accounts {
|
||||
copy[hash] = blob
|
||||
}
|
||||
maps.Copy(copy, accounts)
|
||||
return copy
|
||||
}
|
||||
|
||||
|
@ -40,9 +39,7 @@ func copyStorage(storage map[common.Hash]map[common.Hash][]byte) map[common.Hash
|
|||
copy := make(map[common.Hash]map[common.Hash][]byte)
|
||||
for accHash, slots := range storage {
|
||||
copy[accHash] = make(map[common.Hash][]byte)
|
||||
for slotHash, blob := range slots {
|
||||
copy[accHash][slotHash] = blob
|
||||
}
|
||||
maps.Copy(copy[accHash], slots)
|
||||
}
|
||||
return copy
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"maps"
|
||||
)
|
||||
|
||||
// TxStatus is the current status of a transaction as seen by the pool.
|
||||
|
@ -390,9 +391,7 @@ func (p *TxPool) Add(txs []*types.Transaction, sync bool) []error {
|
|||
func (p *TxPool) Pending(filter PendingFilter) map[common.Address][]*LazyTransaction {
|
||||
txs := make(map[common.Address][]*LazyTransaction)
|
||||
for _, subpool := range p.subpools {
|
||||
for addr, set := range subpool.Pending(filter) {
|
||||
txs[addr] = set
|
||||
}
|
||||
maps.Copy(txs, subpool.Pending(filter))
|
||||
}
|
||||
return txs
|
||||
}
|
||||
|
@ -445,12 +444,8 @@ func (p *TxPool) Content() (map[common.Address][]*types.Transaction, map[common.
|
|||
for _, subpool := range p.subpools {
|
||||
run, block := subpool.Content()
|
||||
|
||||
for addr, txs := range run {
|
||||
runnable[addr] = txs
|
||||
}
|
||||
for addr, txs := range block {
|
||||
blocked[addr] = txs
|
||||
}
|
||||
maps.Copy(runnable, run)
|
||||
maps.Copy(blocked, block)
|
||||
}
|
||||
return runnable, blocked
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"maps"
|
||||
)
|
||||
|
||||
// ClientOption is a configuration option for the RPC client.
|
||||
|
@ -89,9 +90,7 @@ func WithHeader(key, value string) ClientOption {
|
|||
func WithHeaders(headers http.Header) ClientOption {
|
||||
return optionFunc(func(cfg *clientConfig) {
|
||||
cfg.initHeaders()
|
||||
for k, vs := range headers {
|
||||
cfg.httpHeaders[k] = vs
|
||||
}
|
||||
maps.Copy(cfg.httpHeaders, headers)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"math"
|
||||
"mime"
|
||||
"net/http"
|
||||
|
@ -146,9 +147,7 @@ func newClientTransportHTTP(endpoint string, cfg *clientConfig) reconnectFunc {
|
|||
headers := make(http.Header, 2+len(cfg.httpHeaders))
|
||||
headers.Set("accept", contentType)
|
||||
headers.Set("content-type", contentType)
|
||||
for key, values := range cfg.httpHeaders {
|
||||
headers[key] = values
|
||||
}
|
||||
maps.Copy(headers, cfg.httpHeaders)
|
||||
|
||||
client := cfg.httpClient
|
||||
if client == nil {
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
mapset "github.com/deckarep/golang-set/v2"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/gorilla/websocket"
|
||||
"maps"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -236,9 +237,7 @@ func newClientTransportWS(endpoint string, cfg *clientConfig) (reconnectFunc, er
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for key, values := range cfg.httpHeaders {
|
||||
header[key] = values
|
||||
}
|
||||
maps.Copy(header, cfg.httpHeaders)
|
||||
|
||||
connect := func(ctx context.Context) (ServerCodec, error) {
|
||||
header := header.Clone()
|
||||
|
|
Loading…
Reference in New Issue