mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-24 09:25:21 +00:00
block: Grow buffer on Trim, avoid reallocations
This commit is contained in:
parent
b8dd284d3d
commit
abc48229a3
1 changed files with 3 additions and 1 deletions
|
@ -107,9 +107,11 @@ func New(stateRootEnabled bool) *Block {
|
|||
// Notice that only the hashes of the transactions are stored.
|
||||
func (b *Block) Trim() ([]byte, error) {
|
||||
buf := io.NewBufBinWriter()
|
||||
numTx := len(b.Transactions)
|
||||
buf.Grow(b.GetExpectedBlockSizeWithoutTransactions(numTx) + util.Uint256Size*numTx)
|
||||
b.Header.EncodeBinary(buf.BinWriter)
|
||||
|
||||
buf.WriteVarUint(uint64(len(b.Transactions)))
|
||||
buf.WriteVarUint(uint64(numTx))
|
||||
for _, tx := range b.Transactions {
|
||||
h := tx.Hash()
|
||||
h.EncodeBinary(buf.BinWriter)
|
||||
|
|
Loading…
Reference in a new issue