Skip to content

Commit

Permalink
fix: types: remove unnecessary/pedantic code from removeZeroCoins (#1…
Browse files Browse the repository at this point in the history
…3967)

Simplifies and makes clearer the code in removeZeroCoins by
removing unnecessary checks that boiled down to still running
in the same final for loop.

Fixes #13958
  • Loading branch information
odeke-em committed Nov 22, 2022
1 parent d6da703 commit 2739f83
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,26 +789,15 @@ func (coins Coins) negative() Coins {

// removeZeroCoins removes all zero coins from the given coin set in-place.
func removeZeroCoins(coins Coins) Coins {
for i := 0; i < len(coins); i++ {
if coins[i].IsZero() {
break
} else if i == len(coins)-1 {
return coins
}
}

var result []Coin
if len(coins) > 0 {
result = make([]Coin, 0, len(coins)-1)
}
nonZeros := make([]Coin, 0, len(coins))

for _, coin := range coins {
if !coin.IsZero() {
result = append(result, coin)
nonZeros = append(nonZeros, coin)
}
}

return result
return nonZeros
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 2739f83

Please sign in to comment.