Skip to content

Commit

Permalink
chore: use std maps (#21763)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Sep 17, 2024
1 parent 7856d22 commit 3314cfb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions simsx/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 5 additions & 6 deletions simsx/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 3314cfb

Please sign in to comment.