From a9183f688ff8134c0985c4196eb38aca0da49001 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 13 Jan 2015 23:59:03 -0600 Subject: [PATCH] Ensure all serialization is using fast path. The writeElement function provides faster serialization for primitives. This commit modifies all instances that call writeElement with a pointer to a primitive or a byte slice to instead use the primitive / writeVarBytes function so the faster serialization paths are used. --- msgalert.go | 10 +++++----- msgmerkleblock.go | 6 +----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/msgalert.go b/msgalert.go index 4aa186a82a..787a01efe4 100644 --- a/msgalert.go +++ b/msgalert.go @@ -149,8 +149,8 @@ type Alert struct { // Serialize encodes the alert to w using the alert protocol encoding format. func (alert *Alert) Serialize(w io.Writer, pver uint32) error { - err := writeElements(w, &alert.Version, - &alert.RelayUntil, &alert.Expiration, &alert.ID, &alert.Cancel) + err := writeElements(w, alert.Version, alert.RelayUntil, + alert.Expiration, alert.ID, alert.Cancel) if err != nil { return err } @@ -166,13 +166,13 @@ func (alert *Alert) Serialize(w io.Writer, pver uint32) error { return err } for i := 0; i < int(count); i++ { - err = writeElement(w, &alert.SetCancel[i]) + err = writeElement(w, alert.SetCancel[i]) if err != nil { return err } } - err = writeElements(w, &alert.MinVer, &alert.MaxVer) + err = writeElements(w, alert.MinVer, alert.MaxVer) if err != nil { return err } @@ -194,7 +194,7 @@ func (alert *Alert) Serialize(w io.Writer, pver uint32) error { } } - err = writeElement(w, &alert.Priority) + err = writeElement(w, alert.Priority) if err != nil { return err } diff --git a/msgmerkleblock.go b/msgmerkleblock.go index b5f2ae36ca..dcdcae9985 100644 --- a/msgmerkleblock.go +++ b/msgmerkleblock.go @@ -131,11 +131,7 @@ func (msg *MsgMerkleBlock) BtcEncode(w io.Writer, pver uint32) error { } } - err = writeVarInt(w, pver, uint64(numFlagBytes)) - if err != nil { - return err - } - err = writeElement(w, msg.Flags) + err = writeVarBytes(w, pver, msg.Flags) if err != nil { return err }