Skip to content

Commit 344d01e

Browse files
authored
core/rawdb: preallocate slice in iterateTransactions (#33690)
Preallocate hashes slice with known length instead of using append in a loop. This avoids multiple reallocations during transaction indexing.
1 parent 56be36f commit 344d01e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

core/rawdb/chain_iterator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
153153
err: err,
154154
}
155155
} else {
156-
var hashes []common.Hash
157-
for _, tx := range body.Transactions {
158-
hashes = append(hashes, tx.Hash())
156+
hashes := make([]common.Hash, len(body.Transactions))
157+
for i, tx := range body.Transactions {
158+
hashes[i] = tx.Hash()
159159
}
160160
result = &blockTxHashes{
161161
hashes: hashes,

0 commit comments

Comments
 (0)