Optimize readOutPoint.

Before: BenchmarkReadOutPoint     500000              2946 ns/op
After:  BenchmarkReadOutPoint    5000000               582 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 07:37:34 -06:00
parent d63e0dd455
commit 73f4ee623b

View file

@ -417,10 +417,17 @@ func NewMsgTx() *MsgTx {
// readOutPoint reads the next sequence of bytes from r as an OutPoint. // readOutPoint reads the next sequence of bytes from r as an OutPoint.
func readOutPoint(r io.Reader, pver uint32, version uint32, op *OutPoint) error { func readOutPoint(r io.Reader, pver uint32, version uint32, op *OutPoint) error {
err := readElements(r, &op.Hash, &op.Index) _, err := io.ReadFull(r, op.Hash[:])
if err != nil { if err != nil {
return err return err
} }
buf := make([]byte, 4)
_, err = io.ReadFull(r, buf)
if err != nil {
return err
}
op.Index = binary.LittleEndian.Uint32(buf)
return nil return nil
} }