Preallocate the tx serialization buffer.
Benchmarking shows this is slightly faster due to avoiding the extra garbage collection in addition to less peak memory usage. ok @davecgh
This commit is contained in:
parent
f1a4dfb86d
commit
eecea4180a
1 changed files with 2 additions and 2 deletions
|
@ -549,9 +549,9 @@ func (*wsNotificationManager) removeSpentRequest(ops map[btcwire.OutPoint]map[ch
|
|||
|
||||
// txHexString returns the serialized transaction encoded in hexadecimal.
|
||||
func txHexString(tx *btcutil.Tx) string {
|
||||
var buf bytes.Buffer
|
||||
buf := bytes.NewBuffer(make([]byte, 0, tx.MsgTx().SerializeSize()))
|
||||
// Ignore Serialize's error, as writing to a bytes.buffer cannot fail.
|
||||
tx.MsgTx().Serialize(&buf)
|
||||
tx.MsgTx().Serialize(buf)
|
||||
return hex.EncodeToString(buf.Bytes())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue