From b2e2fd067fc22f98f3e35691d4e705a6c2393149 Mon Sep 17 00:00:00 2001 From: cuiweixie Date: Fri, 29 Mar 2024 10:40:57 +0800 Subject: [PATCH] eth/fetcher: using slices.Clone to simplify codes --- eth/fetcher/tx_fetcher.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/eth/fetcher/tx_fetcher.go b/eth/fetcher/tx_fetcher.go index 18c5ff007a..3fbaf7a1ea 100644 --- a/eth/fetcher/tx_fetcher.go +++ b/eth/fetcher/tx_fetcher.go @@ -22,6 +22,7 @@ import ( "fmt" "math" mrand "math/rand" + "slices" "sort" "time" @@ -973,8 +974,7 @@ func (f *TxFetcher) forEachAnnounce(announces map[common.Hash]*txMetadata, do fu // rotateStrings rotates the contents of a slice by n steps. This method is only // used in tests to simulate random map iteration but keep it deterministic. func rotateStrings(slice []string, n int) { - orig := make([]string, len(slice)) - copy(orig, slice) + orig := slices.Clone(slice) for i := 0; i < len(orig); i++ { slice[i] = orig[(i+n)%len(orig)] @@ -996,8 +996,7 @@ func sortHashes(slice []common.Hash) { // rotateHashes rotates the contents of a slice by n steps. This method is only // used in tests to simulate random map iteration but keep it deterministic. func rotateHashes(slice []common.Hash, n int) { - orig := make([]common.Hash, len(slice)) - copy(orig, slice) + orig := slices.Clone(slice) for i := 0; i < len(orig); i++ { slice[i] = orig[(i+n)%len(orig)]