Skip to content

Commit

Permalink
Types speedups
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored and czarcas7ic committed May 9, 2024
1 parent bbb9a48 commit 8628b48
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
4 changes: 0 additions & 4 deletions math/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,6 @@ func (i Int) Mul(i2 Int) (res Int) {
panic("Int overflow")
}
res = Int{mul(i.i, i2.i)}
// Check overflow if sign of both are same
if res.i.BitLen() > MaxBitLen {
panic("Int overflow")
}
return
}

Expand Down
7 changes: 3 additions & 4 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ func (coins Coins) Add(coinsB ...Coin) Coins {
return coins.safeAdd(coinsB)
}

var zeroInt = math.NewInt(0)

// safeAdd will perform addition of two coins sets. If both coin sets are
// empty, then an empty set is returned. If only a single set is empty, the
// other set is returned. Otherwise, the coins are compared in order of their
Expand All @@ -339,7 +341,7 @@ func (coins Coins) safeAdd(coinsB Coins) (coalesced Coins) {
}

for denom, cL := range uniqCoins { //#nosec
comboCoin := Coin{Denom: denom, Amount: math.NewInt(0)}
comboCoin := Coin{Denom: denom, Amount: zeroInt}
for _, c := range cL {
comboCoin = comboCoin.Add(c)
}
Expand Down Expand Up @@ -820,9 +822,6 @@ var _ sort.Interface = Coins{}

// Sort is a helper function to sort the set of coins in-place
func (coins Coins) Sort() Coins {
// sort.Sort(coins) does a costly runtime copy as part of `runtime.convTSlice`
// So we avoid this heap allocation if len(coins) <= 1. In the future, we should hopefully find
// a strategy to always avoid this.
if len(coins) > 1 {
sort.Sort(coins)
}
Expand Down

0 comments on commit 8628b48

Please sign in to comment.