From 5b6c5af704030014471e8387c5fc27796b6a0356 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 9 Dec 2019 18:25:15 +0300 Subject: [PATCH] *: implement EncodeBinary with pointer receivers where appropriate Everywhere except ParamType (which is just a byte), reduce copying things around for no real reason. --- pkg/consensus/payload.go | 2 +- pkg/core/account_state.go | 2 +- pkg/core/block.go | 3 ++- pkg/core/notification_event.go | 2 +- pkg/util/uint256.go | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/consensus/payload.go b/pkg/consensus/payload.go index f8f635314..52ba5c4b8 100644 --- a/pkg/consensus/payload.go +++ b/pkg/consensus/payload.go @@ -160,7 +160,7 @@ func (p *Payload) SetHeight(h uint32) { } // EncodeBinaryUnsigned writes payload to w excluding signature. -func (p Payload) EncodeBinaryUnsigned(w *io.BinWriter) { +func (p *Payload) EncodeBinaryUnsigned(w *io.BinWriter) { w.WriteLE(p.version) w.WriteBytes(p.prevHash[:]) w.WriteLE(p.height) diff --git a/pkg/core/account_state.go b/pkg/core/account_state.go index daf07b805..cd79fe189 100644 --- a/pkg/core/account_state.go +++ b/pkg/core/account_state.go @@ -140,7 +140,7 @@ func (u *UnspentBalance) DecodeBinary(r *io.BinReader) { } // EncodeBinary implements io.Serializable interface. -func (u UnspentBalance) EncodeBinary(w *io.BinWriter) { +func (u *UnspentBalance) EncodeBinary(w *io.BinWriter) { u.Tx.EncodeBinary(w) w.WriteLE(u.Index) w.WriteLE(u.Value) diff --git a/pkg/core/block.go b/pkg/core/block.go index e1e898ed7..2a6af8d27 100644 --- a/pkg/core/block.go +++ b/pkg/core/block.go @@ -115,7 +115,8 @@ func (b *Block) Trim() ([]byte, error) { buf.WriteVarUint(uint64(len(b.Transactions))) for _, tx := range b.Transactions { - tx.Hash().EncodeBinary(buf.BinWriter) + h := tx.Hash() + h.EncodeBinary(buf.BinWriter) } if buf.Err != nil { return nil, buf.Err diff --git a/pkg/core/notification_event.go b/pkg/core/notification_event.go index fc1c6e727..ee0086cc3 100644 --- a/pkg/core/notification_event.go +++ b/pkg/core/notification_event.go @@ -56,7 +56,7 @@ func getAppExecResultFromStore(s storage.Store, hash util.Uint256) (*AppExecResu } // EncodeBinary implements the Serializable interface. -func (ne NotificationEvent) EncodeBinary(w *io.BinWriter) { +func (ne *NotificationEvent) EncodeBinary(w *io.BinWriter) { w.WriteBytes(ne.ScriptHash[:]) vm.EncodeBinaryStackItem(ne.Item, w) } diff --git a/pkg/util/uint256.go b/pkg/util/uint256.go index 81521e1b8..b8b5588bf 100644 --- a/pkg/util/uint256.go +++ b/pkg/util/uint256.go @@ -117,7 +117,7 @@ func (u Uint256) MarshalJSON() ([]byte, error) { func (u Uint256) CompareTo(other Uint256) int { return bytes.Compare(u[:], other[:]) } // EncodeBinary implements io.Serializable interface. -func (u Uint256) EncodeBinary(w *io.BinWriter) { +func (u *Uint256) EncodeBinary(w *io.BinWriter) { w.WriteBytes(u[:]) }