From 4df58bb2d67d3566d57487e4bf2ddbdf2213846e Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Wed, 25 May 2022 06:50:11 -0400 Subject: [PATCH] Use map[ClaimID] instead of map[string] since conversion ClaimID -> string entails lots of temporary allocations. --- blockchain/claimtrie.go | 4 ++-- claimtrie/change/claimid.go | 4 ++-- claimtrie/node/node.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/blockchain/claimtrie.go b/blockchain/claimtrie.go index f821537a..0bf89978 100644 --- a/blockchain/claimtrie.go +++ b/blockchain/claimtrie.go @@ -35,7 +35,7 @@ func (b *BlockChain) ParseClaimScripts(block *btcutil.Block, bn *blockNode, view ht := block.Height() for _, tx := range block.Transactions() { - h := handler{ht, tx, view, map[string][]byte{}} + h := handler{ht, tx, view, map[change.ClaimID][]byte{}} if err := h.handleTxIns(b.claimTrie); err != nil { return err } @@ -67,7 +67,7 @@ type handler struct { ht int32 tx *btcutil.Tx view *UtxoViewpoint - spent map[string][]byte + spent map[change.ClaimID][]byte } func (h *handler) handleTxIns(ct *claimtrie.ClaimTrie) error { diff --git a/claimtrie/change/claimid.go b/claimtrie/change/claimid.go index e7a92565..b05f4983 100644 --- a/claimtrie/change/claimid.go +++ b/claimtrie/change/claimid.go @@ -39,8 +39,8 @@ func NewIDFromString(s string) (id ClaimID, err error) { } // Key is for in-memory maps -func (id ClaimID) Key() string { - return string(id[:]) +func (id ClaimID) Key() ClaimID { + return id } // String is for anything written to a DB diff --git a/claimtrie/node/node.go b/claimtrie/node/node.go index ff45fc11..2e072d27 100644 --- a/claimtrie/node/node.go +++ b/claimtrie/node/node.go @@ -14,12 +14,12 @@ type Node struct { TakenOverAt int32 // The height at when the current BestClaim took over. Claims ClaimList // List of all Claims. Supports ClaimList // List of all Supports, including orphaned ones. - SupportSums map[string]int64 + SupportSums map[change.ClaimID]int64 } // New returns a new node. func New() *Node { - return &Node{SupportSums: map[string]int64{}} + return &Node{SupportSums: map[change.ClaimID]int64{}} } func (n *Node) HasActiveBestClaim() bool { @@ -166,7 +166,7 @@ func (n *Node) handleExpiredAndActivated(height int32) int { } changes := 0 - update := func(items ClaimList, sums map[string]int64) ClaimList { + update := func(items ClaimList, sums map[change.ClaimID]int64) ClaimList { for i := 0; i < len(items); i++ { c := items[i] if c.Status == Accepted && c.ActiveAt <= height && c.VisibleAt <= height { @@ -343,7 +343,7 @@ func (n *Node) SortClaimsByBid() { func (n *Node) Clone() *Node { clone := New() if n.SupportSums != nil { - clone.SupportSums = map[string]int64{} + clone.SupportSums = map[change.ClaimID]int64{} for key, value := range n.SupportSums { clone.SupportSums[key] = value }