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()
|
ht := block.Height()
|
||||||
|
|
||||||
for _, tx := range block.Transactions() {
|
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 {
|
if err := h.handleTxIns(b.claimTrie); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ type handler struct {
|
||||||
ht int32
|
ht int32
|
||||||
tx *btcutil.Tx
|
tx *btcutil.Tx
|
||||||
view *UtxoViewpoint
|
view *UtxoViewpoint
|
||||||
spent map[string][]byte
|
spent map[change.ClaimID][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) handleTxIns(ct *claimtrie.ClaimTrie) error {
|
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
|
// Key is for in-memory maps
|
||||||
func (id ClaimID) Key() string {
|
func (id ClaimID) Key() ClaimID {
|
||||||
return string(id[:])
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
// String is for anything written to a DB
|
// 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.
|
TakenOverAt int32 // The height at when the current BestClaim took over.
|
||||||
Claims ClaimList // List of all Claims.
|
Claims ClaimList // List of all Claims.
|
||||||
Supports ClaimList // List of all Supports, including orphaned ones.
|
Supports ClaimList // List of all Supports, including orphaned ones.
|
||||||
SupportSums map[string]int64
|
SupportSums map[change.ClaimID]int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new node.
|
// New returns a new node.
|
||||||
func New() *Node {
|
func New() *Node {
|
||||||
return &Node{SupportSums: map[string]int64{}}
|
return &Node{SupportSums: map[change.ClaimID]int64{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) HasActiveBestClaim() bool {
|
func (n *Node) HasActiveBestClaim() bool {
|
||||||
|
@ -166,7 +166,7 @@ func (n *Node) handleExpiredAndActivated(height int32) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
changes := 0
|
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++ {
|
for i := 0; i < len(items); i++ {
|
||||||
c := items[i]
|
c := items[i]
|
||||||
if c.Status == Accepted && c.ActiveAt <= height && c.VisibleAt <= height {
|
if c.Status == Accepted && c.ActiveAt <= height && c.VisibleAt <= height {
|
||||||
|
@ -343,7 +343,7 @@ func (n *Node) SortClaimsByBid() {
|
||||||
func (n *Node) Clone() *Node {
|
func (n *Node) Clone() *Node {
|
||||||
clone := New()
|
clone := New()
|
||||||
if n.SupportSums != nil {
|
if n.SupportSums != nil {
|
||||||
clone.SupportSums = map[string]int64{}
|
clone.SupportSums = map[change.ClaimID]int64{}
|
||||||
for key, value := range n.SupportSums {
|
for key, value := range n.SupportSums {
|
||||||
clone.SupportSums[key] = value
|
clone.SupportSums[key] = value
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue