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.
This commit is contained in:
parent
ab8c8e2d39
commit
a7e3ee6aeb
1 changed files with 4 additions and 2 deletions
6
msgtx.go
6
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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue