Optimize writeOutPoint.
Before: BenchmarkWriteOutPoint 500000 2664 ns/op After: BenchmarkWriteOutPoint 10000000 151 ns/op This is part ef the ongoing effort to optimize serialization as noted in conformal/btcd#27.
This commit is contained in:
parent
547b648702
commit
f54b010e4b
1 changed files with 9 additions and 1 deletions
10
msgtx.go
10
msgtx.go
|
@ -6,6 +6,7 @@ package btcwire
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
@ -426,7 +427,14 @@ func readOutPoint(r io.Reader, pver uint32, version uint32, op *OutPoint) error
|
|||
// writeOutPoint encodes op to the bitcoin protocol encoding for an OutPoint
|
||||
// to w.
|
||||
func writeOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error {
|
||||
err := writeElements(w, op.Hash, op.Index)
|
||||
_, err := w.Write(op.Hash[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf := make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(buf, op.Index)
|
||||
_, err = w.Write(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue