forked from TrueCloudLab/neoneo-go
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