Skip to content

Commit

Permalink
Types speedups
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon committed Dec 22, 2023
1 parent fce3312 commit cc29414
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 0 additions & 4 deletions math/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,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
8 changes: 6 additions & 2 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ func (coins Coins) Add(coinsB ...Coin) Coins {
return coins.safeAdd(coinsB)
}

var zeroInt = 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 @@ -335,7 +337,7 @@ func (coins Coins) safeAdd(coinsB Coins) (coalesced Coins) {
}

for denom, cL := range uniqCoins { //#nosec
comboCoin := Coin{Denom: denom, Amount: NewInt(0)}
comboCoin := Coin{Denom: denom, Amount: zeroInt}
for _, c := range cL {
comboCoin = comboCoin.Add(c)
}
Expand Down Expand Up @@ -827,7 +829,9 @@ 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)
if len(coins) > 1 {
sort.Sort(coins)
}
return coins
}

Expand Down

0 comments on commit cc29414

Please sign in to comment.