From 8cd9b20cbcd77883d3d166e65de38196bcd08498 Mon Sep 17 00:00:00 2001 From: lido333 Date: Tue, 1 Apr 2025 00:26:44 +0800 Subject: [PATCH] chore: slices Delete (#24164) Co-authored-by: Alex | Interchain Labs --- types/mempool/sender_nonce.go | 3 ++- x/staking/types/delegation.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/types/mempool/sender_nonce.go b/types/mempool/sender_nonce.go index 6895997076..4d4d33e545 100644 --- a/types/mempool/sender_nonce.go +++ b/types/mempool/sender_nonce.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "math/rand" // #nosec // math/rand is used for random selection and seeded from crypto/rand + "slices" "sync" "github.com/huandu/skiplist" @@ -307,5 +308,5 @@ func (i *senderNonceMempoolIterator) Tx() sdk.Tx { } func removeAtIndex[T any](slice []T, index int) []T { - return append(slice[:index], slice[index+1:]...) + return slices.Delete(slice, index, index+1) } diff --git a/x/staking/types/delegation.go b/x/staking/types/delegation.go index 3284316246..0379504355 100644 --- a/x/staking/types/delegation.go +++ b/x/staking/types/delegation.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "slices" "strings" "time" @@ -159,7 +160,7 @@ func (ubd *UnbondingDelegation) AddEntry(creationHeight int64, minTime time.Time // RemoveEntry - remove entry at index i to the unbonding delegation func (ubd *UnbondingDelegation) RemoveEntry(i int64) { - ubd.Entries = append(ubd.Entries[:i], ubd.Entries[i+1:]...) + ubd.Entries = slices.Delete(ubd.Entries, int(i), int(i+1)) } // return the unbonding delegation @@ -251,7 +252,7 @@ func (red *Redelegation) AddEntry(creationHeight int64, minTime time.Time, balan // RemoveEntry - remove entry at index i to the unbonding delegation func (red *Redelegation) RemoveEntry(i int64) { - red.Entries = append(red.Entries[:i], red.Entries[i+1:]...) + red.Entries = slices.Delete(red.Entries, int(i), int(i+1)) } // MustMarshalRED returns the Redelegation bytes. Panics if fails.