File tree Expand file tree Collapse file tree 3 files changed +10
-19
lines changed Expand file tree Collapse file tree 3 files changed +10
-19
lines changed Original file line number Diff line number Diff line change 1717package state
1818
1919import (
20+ "maps"
21+
2022 "github.com/ethereum/go-ethereum/common"
2123)
2224
@@ -57,16 +59,10 @@ func newAccessList() *accessList {
5759// Copy creates an independent copy of an accessList.
5860func (a * accessList ) Copy () * accessList {
5961 cp := newAccessList ()
60- for k , v := range a .addresses {
61- cp .addresses [k ] = v
62- }
62+ cp .addresses = maps .Clone (a .addresses )
6363 cp .slots = make ([]map [common.Hash ]struct {}, len (a .slots ))
6464 for i , slotMap := range a .slots {
65- newSlotmap := make (map [common.Hash ]struct {}, len (slotMap ))
66- for k := range slotMap {
67- newSlotmap [k ] = struct {}{}
68- }
69- cp .slots [i ] = newSlotmap
65+ cp .slots [i ] = maps .Clone (slotMap )
7066 }
7167 return cp
7268}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import (
2020 "bytes"
2121 "fmt"
2222 "io"
23+ "maps"
2324 "time"
2425
2526 "github.com/ethereum/go-ethereum/common"
@@ -47,11 +48,7 @@ func (s Storage) String() (str string) {
4748}
4849
4950func (s Storage ) Copy () Storage {
50- cpy := make (Storage , len (s ))
51- for key , value := range s {
52- cpy [key ] = value
53- }
54- return cpy
51+ return maps .Clone (s )
5552}
5653
5754// stateObject represents an Ethereum account which is being modified.
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ package state
1919
2020import (
2121 "fmt"
22+ "maps"
2223 "math/big"
2324 "slices"
2425 "sort"
@@ -750,9 +751,8 @@ func (s *StateDB) Copy() *StateDB {
750751 state .stateObjectsDirty [addr ] = struct {}{}
751752 }
752753 // Deep copy the destruction markers.
753- for addr , value := range s .stateObjectsDestruct {
754- state .stateObjectsDestruct [addr ] = value
755- }
754+ state .stateObjectsDestruct = maps .Clone (s .stateObjectsDestruct )
755+
756756 // Deep copy the state changes made in the scope of block
757757 // along with their original values.
758758 state .accounts = copySet (s .accounts )
@@ -770,9 +770,7 @@ func (s *StateDB) Copy() *StateDB {
770770 state .logs [hash ] = cpy
771771 }
772772 // Deep copy the preimages occurred in the scope of block
773- for hash , preimage := range s .preimages {
774- state .preimages [hash ] = preimage
775- }
773+ state .preimages = maps .Clone (s .preimages )
776774 // Do we need to copy the access list and transient storage?
777775 // In practice: No. At the start of a transaction, these two lists are empty.
778776 // In practice, we only ever copy state _between_ transactions/blocks, never
You can’t perform that action at this time.
0 commit comments