Use map[ClaimID] instead of map[string] since conversion ClaimID -> string entails lots of temporary allocations.
This commit is contained in:
parent
4159712b92
commit
4df58bb2d6
3 changed files with 8 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue