From 3314cfb8994eb3ad152469a7c8b529d2009f29af Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 17 Sep 2024 09:48:42 +0200 Subject: [PATCH] chore: use std maps (#21763) --- go.mod | 2 +- simsx/registry.go | 8 ++++---- simsx/reporter.go | 11 +++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index ba2ea2a21919..ab8bd9738c9e 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,6 @@ require ( github.com/tendermint/go-amino v0.16.0 gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b golang.org/x/crypto v0.27.0 - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc golang.org/x/sync v0.8.0 google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 google.golang.org/grpc v1.66.2 @@ -161,6 +160,7 @@ require ( go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect + golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/sys v0.25.0 // indirect diff --git a/simsx/registry.go b/simsx/registry.go index ce2e34bb29f9..3fdd5da0d626 100644 --- a/simsx/registry.go +++ b/simsx/registry.go @@ -3,13 +3,12 @@ package simsx import ( "context" "iter" + "maps" "math/rand" "slices" "strings" "time" - "golang.org/x/exp/maps" - "cosmossdk.io/core/address" "cosmossdk.io/core/log" @@ -170,11 +169,12 @@ func (s UniqueTypeRegistry) Add(weight uint32, f SimMsgFactoryX) { // Iterator returns an iterator function for a Go for loop sorted by weight desc. func (s UniqueTypeRegistry) Iterator() iter.Seq2[uint32, SimMsgFactoryX] { x := maps.Values(s) - slices.SortFunc(x, func(a, b WeightedFactory) int { + sortedWeightedFactory := slices.SortedFunc(x, func(a, b WeightedFactory) int { return a.Compare(b) }) + return func(yield func(uint32, SimMsgFactoryX) bool) { - for _, v := range x { + for _, v := range sortedWeightedFactory { if !yield(v.Weight, v.Factory) { return } diff --git a/simsx/reporter.go b/simsx/reporter.go index a70491a31b74..726430fcdd42 100644 --- a/simsx/reporter.go +++ b/simsx/reporter.go @@ -3,14 +3,12 @@ package simsx import ( "errors" "fmt" + "maps" "slices" - "sort" "strings" "sync" "sync/atomic" - "golang.org/x/exp/maps" - sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -237,14 +235,15 @@ func (s *ExecutionSummary) Add(module, url string, status ReporterStatus, commen func (s *ExecutionSummary) String() string { s.mx.RLock() defer s.mx.RUnlock() - keys := maps.Keys(s.counts) - sort.Strings(keys) + keys := slices.Sorted(maps.Keys(s.counts)) var sb strings.Builder for _, key := range keys { sb.WriteString(fmt.Sprintf("%s: %d\n", key, s.counts[key])) } for m, c := range s.skipReasons { - sb.WriteString(fmt.Sprintf("%d\t%s: %q\n", sum(maps.Values(c)), m, maps.Keys(c))) + values := maps.Values(c) + keys := maps.Keys(c) + sb.WriteString(fmt.Sprintf("%d\t%s: %q\n", sum(slices.Collect(values)), m, slices.Collect(keys))) } return sb.String() }