mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
cmd/utils: prealloc + clear map
This commit is contained in:
parent
127d1f42bb
commit
a584b07b23
1 changed files with 2 additions and 2 deletions
|
|
@ -512,7 +512,7 @@ func ImportPreimages(db ethdb.Database, fn string) error {
|
||||||
stream := rlp.NewStream(reader, 0)
|
stream := rlp.NewStream(reader, 0)
|
||||||
|
|
||||||
// Import the preimages in batches to prevent disk thrashing
|
// Import the preimages in batches to prevent disk thrashing
|
||||||
preimages := make(map[common.Hash][]byte)
|
preimages := make(map[common.Hash][]byte, 1024)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Read the next entry and ensure it's not junk
|
// Read the next entry and ensure it's not junk
|
||||||
|
|
@ -528,7 +528,7 @@ func ImportPreimages(db ethdb.Database, fn string) error {
|
||||||
preimages[crypto.Keccak256Hash(blob)] = common.CopyBytes(blob)
|
preimages[crypto.Keccak256Hash(blob)] = common.CopyBytes(blob)
|
||||||
if len(preimages) > 1024 {
|
if len(preimages) > 1024 {
|
||||||
rawdb.WritePreimages(db, preimages)
|
rawdb.WritePreimages(db, preimages)
|
||||||
preimages = make(map[common.Hash][]byte)
|
clear(preimages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Flush the last batch preimage data
|
// Flush the last batch preimage data
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue