trie: avoid un-needed map copy (#30343)

This change avoids the an unnecessary map copy if the preimage recording is not enabled.
This commit is contained in:
rjl493456442 2024-08-23 18:27:06 +08:00 committed by GitHub
parent ada20c09dc
commit 020f026616
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -250,11 +250,11 @@ func (t *StateTrie) Witness() map[string]struct{} {
func (t *StateTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet) {
// Write all the pre-images to the actual disk database
if len(t.getSecKeyCache()) > 0 {
preimages := make(map[common.Hash][]byte, len(t.secKeyCache))
for hk, key := range t.secKeyCache {
preimages[common.BytesToHash([]byte(hk))] = key
}
if t.preimages != nil {
preimages := make(map[common.Hash][]byte, len(t.secKeyCache))
for hk, key := range t.secKeyCache {
preimages[common.BytesToHash([]byte(hk))] = key
}
t.preimages.InsertPreimage(preimages)
}
t.secKeyCache = make(map[string][]byte)