From a7e3ee6aebc928fb5baa6595fb2f7ab797552a15 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 6 Nov 2013 15:29:39 -0600 Subject: [PATCH] Optimize writeTxOut. Before: BenchmarkWriteTxOut 500000 4050 ns/op After: BenchmarkWriteTxOut 10000000 248 ns/op This is part ef the ongoing effort to optimize serialization as noted in conformal/btcd#27. --- msgtx.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/msgtx.go b/msgtx.go index cf75bead8..31bcc03c6 100644 --- a/msgtx.go +++ b/msgtx.go @@ -552,7 +552,9 @@ func readTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error { // writeTxOut encodes to into the bitcoin protocol encoding for a transaction // output (TxOut) to w. func writeTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error { - err := writeElement(w, to.Value) + buf := make([]byte, 8) + binary.LittleEndian.PutUint64(buf, uint64(to.Value)) + _, err := w.Write(buf) if err != nil { return err } @@ -563,7 +565,7 @@ func writeTxOut(w io.Writer, pver uint32, version uint32, to *TxOut) error { return err } - err = writeElement(w, to.PkScript) + _, err = w.Write(to.PkScript) if err != nil { return err }