Skip to content

Commit fa5a6e9

Browse files
authored
refactor: use strings.Builder to improve performance (#1211)
Signed-off-by: pennylees <[email protected]>
1 parent eccfb82 commit fa5a6e9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

x/nft/keeper/invariants.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package keeper
66

77
import (
88
"fmt"
9+
"strings"
910

1011
"github.com/crypto-org-chain/chain-main/v8/x/nft/types"
1112

@@ -28,7 +29,7 @@ func AllInvariants(k Keeper) sdk.Invariant {
2829
func SupplyInvariant(k Keeper) sdk.Invariant {
2930
return func(ctx sdk.Context) (string, bool) {
3031
ownersCollectionsSupply := make(map[string]uint64)
31-
var msg string
32+
var msg strings.Builder
3233
count := 0
3334

3435
owners, err := k.GetOwners(ctx)
@@ -45,19 +46,19 @@ func SupplyInvariant(k Keeper) sdk.Invariant {
4546
for denom, supply := range ownersCollectionsSupply {
4647
if supply != k.GetTotalSupply(ctx, denom) {
4748
count++
48-
msg += fmt.Sprintf(
49+
msg.WriteString(fmt.Sprintf(
4950
"total %s NFTs supply invariance:\n"+
5051
"\ttotal %s NFTs supply: %d\n"+
5152
"\tsum of %s NFTs by owner: %d\n",
5253
denom, denom, supply, denom, ownersCollectionsSupply[denom],
53-
)
54+
))
5455
}
5556
}
5657
broken := count != 0
5758

5859
return sdk.FormatInvariant(
5960
types.ModuleName, "supply",
60-
fmt.Sprintf("%d NFT supply invariants found\n%s", count, msg),
61+
fmt.Sprintf("%d NFT supply invariants found\n%s", count, msg.String()),
6162
), broken
6263
}
6364
}

0 commit comments

Comments
 (0)