Optimize readTxOut.

Before: BenchmarkReadTxOut        500000              4576 ns/op
After:  BenchmarkReadTxOut       2000000               871 ns/op

This is part ef the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
This commit is contained in:
Dave Collins 2013-11-06 15:49:26 -06:00
parent 0228508172
commit cece305f78

View file

@ -519,7 +519,9 @@ func writeTxIn(w io.Writer, pver uint32, version uint32, ti *TxIn) error {
// readTxOut reads the next sequence of bytes from r as a transaction output // readTxOut reads the next sequence of bytes from r as a transaction output
// (TxOut). // (TxOut).
func readTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error { func readTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error {
err := readElement(r, &to.Value) buf := make([]byte, 8)
_, err := io.ReadFull(r, buf)
to.Value = int64(binary.LittleEndian.Uint64(buf))
if err != nil { if err != nil {
return err return err
} }
@ -540,7 +542,7 @@ func readTxOut(r io.Reader, pver uint32, version uint32, to *TxOut) error {
} }
b := make([]byte, count) b := make([]byte, count)
err = readElement(r, b) _, err = io.ReadFull(r, b)
if err != nil { if err != nil {
return err return err
} }