diff --git a/x/exchange/genesis.go b/x/exchange/genesis.go index 97d7c9bdc2..1d1662cf16 100644 --- a/x/exchange/genesis.go +++ b/x/exchange/genesis.go @@ -19,7 +19,7 @@ func (g GenesisState) Validate() error { } } - marketIDs := make(map[uint32]int) + marketIDs := make(map[uint32]int, len(g.Markets)) for i, market := range g.Markets { if market.MarketId == 0 { errs = append(errs, fmt.Errorf("invalid market[%d]: market id cannot be zero", i)) @@ -39,7 +39,7 @@ func (g GenesisState) Validate() error { } maxOrderID := uint64(0) - orderIDs := make(map[uint64]int) + orderIDs := make(map[uint64]int, len(g.Orders)) for i, order := range g.Orders { if order.OrderId != 0 { j, seen := orderIDs[order.OrderId] diff --git a/x/exchange/keeper/fulfillment.go b/x/exchange/keeper/fulfillment.go index 45f2f0cedc..e6733c48bc 100644 --- a/x/exchange/keeper/fulfillment.go +++ b/x/exchange/keeper/fulfillment.go @@ -62,9 +62,9 @@ func (k Keeper) FillBids(ctx sdk.Context, msg *exchange.MsgFillBidsRequest) erro var totalSellerFee sdk.Coins assetOutputs := make([]banktypes.Output, 0, len(msg.BidOrderIds)) priceInputs := make([]banktypes.Input, 0, len(msg.BidOrderIds)) - addrIndex := make(map[string]int) + addrIndex := make(map[string]int, len(msg.BidOrderIds)) feeInputs := make([]banktypes.Input, 0, len(msg.BidOrderIds)+1) - feeAddrIndex := make(map[string]int) + feeAddrIndex := make(map[string]int, len(msg.BidOrderIds)) filledOrders := make([]*exchange.FilledOrder, 0, len(msg.BidOrderIds)) for _, order := range orders { bidOrder := order.GetBidOrder() @@ -192,9 +192,9 @@ func (k Keeper) FillAsks(ctx sdk.Context, msg *exchange.MsgFillAsksRequest) erro var errs []error assetInputs := make([]banktypes.Input, 0, len(msg.AskOrderIds)) priceOutputs := make([]banktypes.Output, 0, len(msg.AskOrderIds)) - addrIndex := make(map[string]int) + addrIndex := make(map[string]int, len(msg.AskOrderIds)) feeInputs := make([]banktypes.Input, 0, len(msg.AskOrderIds)+1) - feeAddrIndex := make(map[string]int) + feeAddrIndex := make(map[string]int, len(msg.AskOrderIds)) filledOrders := make([]*exchange.FilledOrder, 0, len(msg.AskOrderIds)) for _, order := range orders { askOrder := order.GetAskOrder() diff --git a/x/exchange/market.go b/x/exchange/market.go index 6e815944f6..ff9cd863bf 100644 --- a/x/exchange/market.go +++ b/x/exchange/market.go @@ -52,8 +52,8 @@ func (m Market) Validate() error { // ValidateFeeOptions returns an error if any of the provide coin values is not a valid fee option. func ValidateFeeOptions(field string, options []sdk.Coin) error { var errs []error - denoms := make(map[string]bool) - dups := make(map[string]bool) + denoms := make(map[string]bool, len(options)) + dups := make(map[string]bool, len(options)) for _, coin := range options { if denoms[coin.Denom] { if !dups[coin.Denom] { @@ -115,7 +115,7 @@ func ValidateFeeRatios(sellerRatios, buyerRatios []FeeRatio) error { } // For the buyer ones, there can be multiple per price denom. - buyerPriceDenomsMap := make(map[string]bool) + buyerPriceDenomsMap := make(map[string]bool, len(buyerRatios)) buyerPriceDenoms := make([]string, 0) for _, ratio := range buyerRatios { if !buyerPriceDenomsMap[ratio.Price.Denom] { @@ -145,7 +145,7 @@ func ValidateSellerFeeRatios(ratios []FeeRatio) error { return nil } - seen := make(map[string]bool) + seen := make(map[string]bool, len(ratios)) dups := make(map[string]bool) var errs []error for _, ratio := range ratios { @@ -177,7 +177,7 @@ func ValidateBuyerFeeRatios(ratios []FeeRatio) error { return nil } - seen := make(map[string]bool) + seen := make(map[string]bool, len(ratios)) dups := make(map[string]bool) var errs []error for _, ratio := range ratios { @@ -337,14 +337,14 @@ func ValidateRatioDenoms(sellerRatios, buyerRatios []FeeRatio) []error { if len(sellerRatios) > 0 && len(buyerRatios) > 0 { // We only need to check the price denoms if *both* types have an entry. sellerPriceDenoms := make([]string, len(sellerRatios)) - sellerPriceDenomsKnown := make(map[string]bool) + sellerPriceDenomsKnown := make(map[string]bool, len(sellerRatios)) for i, ratio := range sellerRatios { sellerPriceDenoms[i] = ratio.Price.Denom sellerPriceDenomsKnown[ratio.Price.Denom] = true } buyerPriceDenoms := make([]string, 0, len(sellerRatios)) - buyerPriceDenomsKnown := make(map[string]bool) + buyerPriceDenomsKnown := make(map[string]bool, len(sellerRatios)) for _, ratio := range buyerRatios { if !buyerPriceDenomsKnown[ratio.Price.Denom] { buyerPriceDenoms = append(buyerPriceDenoms, ratio.Price.Denom) @@ -414,7 +414,7 @@ func ValidateAccessGrantsField(field string, accessGrants []AccessGrant) error { field += " " } errs := make([]error, len(accessGrants)) - seen := make(map[string]bool) + seen := make(map[string]bool, len(accessGrants)) dups := make(map[string]bool) for i, ag := range accessGrants { if seen[ag.Address] && !dups[ag.Address] { @@ -446,7 +446,7 @@ func (a AccessGrant) ValidateInField(field string) error { if len(a.Permissions) == 0 { return fmt.Errorf("invalid %saccess grant: no permissions provided for %s", field, a.Address) } - seen := make(map[Permission]bool) + seen := make(map[Permission]bool, len(a.Permissions)) for _, perm := range a.Permissions { if seen[perm] { return fmt.Errorf("invalid %saccess grant: %s appears multiple times for %s", field, perm.SimpleString(), a.Address) @@ -568,7 +568,7 @@ func ValidateReqAttrsAreNormalized(field string, attrs []string) error { // ValidateReqAttrs makes sure that each provided attribute is valid and that no duplicate entries are provided. func ValidateReqAttrs(field string, attrs []string) error { var errs []error - seen := make(map[string]bool) + seen := make(map[string]bool, len(attrs)) bad := make(map[string]bool) for _, attr := range attrs { normalized := nametypes.NormalizeName(attr) diff --git a/x/exchange/msg.go b/x/exchange/msg.go index 8cd13b79c7..1d0bd7893c 100644 --- a/x/exchange/msg.go +++ b/x/exchange/msg.go @@ -315,7 +315,7 @@ func (m MsgMarketManagePermissionsRequest) ValidateBasic() error { errs = append(errs, err) } - toRevokeByAddr := make(map[string]AccessGrant) + toRevokeByAddr := make(map[string]AccessGrant, len(m.ToRevoke)) for _, ag := range m.ToRevoke { if ContainsString(m.RevokeAll, ag.Address) { errs = append(errs, fmt.Errorf("address %s appears in both the revoke-all and to-revoke fields", ag.Address)) diff --git a/x/exchange/orders.go b/x/exchange/orders.go index 10caa617f1..74e1877377 100644 --- a/x/exchange/orders.go +++ b/x/exchange/orders.go @@ -51,7 +51,7 @@ var _ OrderI = (*Order)(nil) // findDuplicateIds returns all order ids that appear two or more times in the provided slice. func findDuplicateIds(orderIDs []uint64) []uint64 { var rv []uint64 - seen := make(map[uint64]bool) + seen := make(map[uint64]bool, len(orderIDs)) dups := make(map[uint64]bool) for _, orderID := range orderIDs { if seen[orderID] && !dups[orderID] {