core: pre-allocate in Copy() #25279 (#1213)

This commit is contained in:
Daniel Liu 2025-07-28 16:57:51 +08:00 committed by GitHub
parent 390ea247d3
commit 52f5766059
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -46,7 +46,7 @@ func (s Storage) String() (str string) {
}
func (s Storage) Copy() Storage {
cpy := make(Storage)
cpy := make(Storage, len(s))
for key, value := range s {
cpy[key] = value
}
@ -251,7 +251,7 @@ func (s *stateObject) SetState(db Database, key, value common.Hash) {
func (s *stateObject) SetStorage(storage map[common.Hash]common.Hash) {
// Allocate fake storage if it's nil.
if s.fakeStorage == nil {
s.fakeStorage = make(Storage)
s.fakeStorage = make(Storage, len(storage))
}
for key, value := range storage {
s.fakeStorage[key] = value

View file

@ -37,7 +37,7 @@ type Storage map[common.Hash]common.Hash
// Copy duplicates the current storage.
func (s Storage) Copy() Storage {
cpy := make(Storage)
cpy := make(Storage, len(s))
for key, value := range s {
cpy[key] = value
}