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