Skip to content

Commit cee5521

Browse files
rjl493456442mask-pp
authored andcommitted
trie: avoid un-needed map copy (ethereum#30343)
This change avoids the an unnecessary map copy if the preimage recording is not enabled.
1 parent 18ebdc9 commit cee5521

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

trie/secure_trie.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ func (t *StateTrie) Witness() map[string]struct{} {
250250
func (t *StateTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet) {
251251
// Write all the pre-images to the actual disk database
252252
if len(t.getSecKeyCache()) > 0 {
253-
preimages := make(map[common.Hash][]byte, len(t.secKeyCache))
254-
for hk, key := range t.secKeyCache {
255-
preimages[common.BytesToHash([]byte(hk))] = key
256-
}
257253
if t.preimages != nil {
254+
preimages := make(map[common.Hash][]byte, len(t.secKeyCache))
255+
for hk, key := range t.secKeyCache {
256+
preimages[common.BytesToHash([]byte(hk))] = key
257+
}
258258
t.preimages.InsertPreimage(preimages)
259259
}
260260
t.secKeyCache = make(map[string][]byte)

0 commit comments

Comments
 (0)