From b134beb3b7809de6370a93cc5f6a684d6942e2e8 Mon Sep 17 00:00:00 2001 From: David Hill Date: Wed, 16 Nov 2016 10:43:17 -0500 Subject: [PATCH] txscript: reduce allocs in calcSignatureHash --- txscript/script.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/txscript/script.go b/txscript/script.go index 4a0d6686..4397f774 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -355,9 +355,9 @@ func calcSignatureHash(script []parsedOpcode, hashType SigHashType, tx *wire.Msg // The final hash is the double sha256 of both the serialized modified // transaction and the hash type (encoded as a 4-byte little-endian // value) appended. - var wbuf bytes.Buffer - txCopy.Serialize(&wbuf) - binary.Write(&wbuf, binary.LittleEndian, hashType) + wbuf := bytes.NewBuffer(make([]byte, 0, txCopy.SerializeSize()+4)) + txCopy.Serialize(wbuf) + binary.Write(wbuf, binary.LittleEndian, hashType) return chainhash.DoubleHashB(wbuf.Bytes()) }