From 1a1f93865f7bda02f26811fdf18a94ec889cfb31 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 6 Nov 2013 16:38:51 -0600 Subject: [PATCH] Optimize writeTxIn. Before: BenchmarkWriteTxIn 5000000 422 ns/op After: BenchmarkWriteTxIn 5000000 389 ns/op This is part of the ongoing effort to optimize serialization as noted in conformal/btcd#27. --- msgtx.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/msgtx.go b/msgtx.go index 2e989fb2..182fb7eb 100644 --- a/msgtx.go +++ b/msgtx.go @@ -504,13 +504,14 @@ func writeTxIn(w io.Writer, pver uint32, version uint32, ti *TxIn) error { return err } - b := []byte(ti.SignatureScript) - _, err = w.Write(b) + _, err = w.Write(ti.SignatureScript) if err != nil { return err } - err = writeElement(w, &ti.Sequence) + buf := make([]byte, 4) + binary.LittleEndian.PutUint32(buf, ti.Sequence) + _, err = w.Write(buf) if err != nil { return err }