Skip to content

Commit

Permalink
more efficient sum
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Mar 27, 2024
1 parent e03100f commit 3555481
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions x/bank/keeper/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ func (k BaseSendKeeper) CreditVirtualAccounts(ctx context.Context) error {
store := sdk.UnwrapSDKContext(ctx).ObjectStore(k.objStoreKey)

var toAddr sdk.AccAddress
var sum sdk.Coins
var sum sdk.MapCoins
flushCurrentAddr := func() {
if sum.IsZero() {
if len(sum) == 0 {
// nothing to flush
return
}

k.addCoins(ctx, toAddr, sum)
sum = sum[:0]
k.addCoins(ctx, toAddr, sum.ToCoins())

Check warning

Code scanning / gosec

Errors unhandled. Warning

Errors unhandled.
clear(sum)

// Create account if recipient does not exist.
//
Expand All @@ -117,9 +118,7 @@ func (k BaseSendKeeper) CreditVirtualAccounts(ctx context.Context) error {
toAddr = addr
}

coins := it.Value().(sdk.Coins)
// TODO more efficient coins sum
sum = sum.Add(coins...)
sum.Add(it.Value().(sdk.Coins)...)
}

flushCurrentAddr()
Expand Down

0 comments on commit 3555481

Please sign in to comment.