From 020f026616782c37ca7cb5ec3c452b5c4c3e1497 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 23 Aug 2024 18:27:06 +0800 Subject: [PATCH] trie: avoid un-needed map copy (#30343) This change avoids the an unnecessary map copy if the preimage recording is not enabled. --- trie/secure_trie.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trie/secure_trie.go b/trie/secure_trie.go index 6eb6defa45..9d19ee58a4 100644 --- a/trie/secure_trie.go +++ b/trie/secure_trie.go @@ -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)