From 6f87ca842f3ac1d9a34692fbbbb72fa93f1421ac Mon Sep 17 00:00:00 2001 From: Will Cory Date: Sat, 12 Aug 2023 14:29:21 -0700 Subject: [PATCH] feat(indexer): Preallocate space for a slice --- indexer/api/routes/deposits.go | 2 +- indexer/api/routes/withdrawals.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indexer/api/routes/deposits.go b/indexer/api/routes/deposits.go index fbb0849d1379..5845ef36bcad 100644 --- a/indexer/api/routes/deposits.go +++ b/indexer/api/routes/deposits.go @@ -30,7 +30,7 @@ type DepositResponse struct { // TODO this is original spec but maybe include the l2 block info too for the relayed tx // FIXME make a pure function that returns a struct instead of newWithdrawalResponse func newDepositResponse(deposits []*database.L1BridgeDepositWithTransactionHashes) DepositResponse { - var items []DepositItem + items := make([]DepositItem, len(deposits)) for _, deposit := range deposits { item := DepositItem{ Guid: deposit.L1BridgeDeposit.TransactionSourceHash.String(), diff --git a/indexer/api/routes/withdrawals.go b/indexer/api/routes/withdrawals.go index 02a57fe155f7..0f125527a540 100644 --- a/indexer/api/routes/withdrawals.go +++ b/indexer/api/routes/withdrawals.go @@ -43,7 +43,7 @@ type WithdrawalResponse struct { // FIXME make a pure function that returns a struct instead of newWithdrawalResponse func newWithdrawalResponse(withdrawals []*database.L2BridgeWithdrawalWithTransactionHashes) WithdrawalResponse { - var items []WithdrawalItem + items := make([]WithdrawalItem, len(withdrawals)) for _, withdrawal := range withdrawals { item := WithdrawalItem{ Guid: withdrawal.L2BridgeWithdrawal.TransactionWithdrawalHash.String(),