Skip to content

Commit b482423

Browse files
trie: reduce allocs in insertPreimage (#21261)
1 parent 93142e5 commit b482423

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎trie/database.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,15 @@ func (db *Database) insert(hash common.Hash, size int, node node) {
349349
}
350350

351351
// insertPreimage writes a new trie node pre-image to the memory database if it's
352-
// yet unknown. The method will make a copy of the slice.
352+
// yet unknown. The method will NOT make a copy of the slice,
353+
// only use if the preimage will NOT be changed later on.
353354
//
354355
// Note, this method assumes that the database's lock is held!
355356
func (db *Database) insertPreimage(hash common.Hash, preimage []byte) {
356357
if _, ok := db.preimages[hash]; ok {
357358
return
358359
}
359-
db.preimages[hash] = common.CopyBytes(preimage)
360+
db.preimages[hash] = preimage
360361
db.preimagesSize += common.StorageSize(common.HashLength + len(preimage))
361362
}
362363

0 commit comments

Comments
 (0)