mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-24 06:47:59 +01:00
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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"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
|
// writeOutPoint encodes op to the bitcoin protocol encoding for an OutPoint
|
||||||
// to w.
|
// to w.
|
||||||
func writeOutPoint(w io.Writer, pver uint32, version uint32, op *OutPoint) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue