chore: use std maps (#21763)

This commit is contained in:
Julien Robert 2024-09-17 09:48:42 +02:00 committed by GitHub
parent 7856d22603
commit 3314cfb899
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

2
go.mod
View File

@ -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

View File

@ -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
}

View File

@ -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()
}