core/rawdb: preallocate slice in iterateTransactions (#33690)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Preallocate hashes slice with known length instead of using append in a
loop. This avoids multiple reallocations during transaction indexing.
This commit is contained in:
Lessa 2026-01-27 20:51:15 -05:00 committed by GitHub
parent 56be36f672
commit 344d01e2be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -153,9 +153,9 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
err: err,
}
} else {
var hashes []common.Hash
for _, tx := range body.Transactions {
hashes = append(hashes, tx.Hash())
hashes := make([]common.Hash, len(body.Transactions))
for i, tx := range body.Transactions {
hashes[i] = tx.Hash()
}
result = &blockTxHashes{
hashes: hashes,