mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
all: use slices.Sort() to sort strings
This commit is contained in:
parent
447b5f7e19
commit
bf48780fcb
21 changed files with 40 additions and 42 deletions
|
|
@ -23,7 +23,6 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
"unicode"
|
||||
|
|
@ -280,7 +279,7 @@ func iterSorted[V any](inp map[string]V, onItem func(string, V) error) error {
|
|||
for key := range inp {
|
||||
sortedKeys = append(sortedKeys, key)
|
||||
}
|
||||
sort.Strings(sortedKeys)
|
||||
slices.Sort(sortedKeys)
|
||||
|
||||
for _, key := range sortedKeys {
|
||||
if err := onItem(key, inp[key]); err != nil {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -90,7 +90,7 @@ func showAttributeCounts(ns nodeSet) {
|
|||
maxlength = len(key)
|
||||
}
|
||||
}
|
||||
sort.Strings(keys)
|
||||
slices.Sort(keys)
|
||||
fmt.Println("ENR attribute counts:")
|
||||
for _, key := range keys {
|
||||
fmt.Printf("%s%s: %d\n", strings.Repeat(" ", maxlength-len(key)+1), key, attrcount[key])
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
"os/signal"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
|
@ -314,7 +314,7 @@ func (c *Console) Welcome() {
|
|||
for api, version := range apis {
|
||||
modules = append(modules, fmt.Sprintf("%s:%s", api, version))
|
||||
}
|
||||
sort.Strings(modules)
|
||||
slices.Sort(modules)
|
||||
message += " modules: " + strings.Join(modules, " ") + "\n"
|
||||
}
|
||||
message += "\nTo exit, press ctrl-d or type exit"
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"encoding/json"
|
||||
"maps"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -56,7 +55,7 @@ func NewWitnessStats() *WitnessStats {
|
|||
func (s *WitnessStats) Add(nodes map[string][]byte, owner common.Hash) {
|
||||
// Extract paths from the nodes map
|
||||
paths := slices.Collect(maps.Keys(nodes))
|
||||
sort.Strings(paths)
|
||||
slices.Sort(paths)
|
||||
|
||||
for i, path := range paths {
|
||||
// If current path is a prefix of the next path, it's not a leaf.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package vm
|
|||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
"slices"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/tracing"
|
||||
|
|
@ -65,7 +65,7 @@ func ActivateableEips() []string {
|
|||
for k := range activators {
|
||||
nums = append(nums, fmt.Sprintf("%d", k))
|
||||
}
|
||||
sort.Strings(nums)
|
||||
slices.Sort(nums)
|
||||
return nums
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
mrand "math/rand"
|
||||
"slices"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
|
|
@ -975,7 +976,7 @@ func (f *TxFetcher) forEachPeer(peers map[string]struct{}, do func(peer string))
|
|||
for peer := range peers {
|
||||
list = append(list, peer)
|
||||
}
|
||||
sort.Strings(list)
|
||||
slices.Sort(list)
|
||||
rotateStrings(list, f.rand.Intn(len(list)))
|
||||
for _, peer := range list {
|
||||
do(peer)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
"bytes"
|
||||
"crypto/rand"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
|
@ -135,7 +134,7 @@ func TestDatabaseSuite(t *testing.T, New func() ethdb.KeyValueStore) {
|
|||
defer db.Close()
|
||||
|
||||
keys := []string{"1", "2", "3", "4", "6", "10", "11", "12", "20", "21", "22"}
|
||||
sort.Strings(keys) // 1, 10, 11, etc
|
||||
slices.Sort(keys) // 1, 10, 11, etc
|
||||
|
||||
for _, k := range keys {
|
||||
if err := db.Put([]byte(k), nil); err != nil {
|
||||
|
|
@ -904,7 +903,7 @@ func iterateKeys(it ethdb.Iterator) []string {
|
|||
for it.Next() {
|
||||
keys = append(keys, string(it.Key()))
|
||||
}
|
||||
sort.Strings(keys)
|
||||
slices.Sort(keys)
|
||||
it.Release()
|
||||
return keys
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package memorydb
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
|
|||
}
|
||||
}
|
||||
// Sort the items and retrieve the associated values
|
||||
sort.Strings(keys)
|
||||
slices.Sort(keys)
|
||||
for _, key := range keys {
|
||||
values = append(values, db.db[key])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -71,6 +71,6 @@ func DiffHashes(a map[string][32]byte, b map[string][32]byte) []string {
|
|||
updates = append(updates, file)
|
||||
}
|
||||
}
|
||||
sort.Strings(updates)
|
||||
slices.Sort(updates)
|
||||
return updates
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/internal/version"
|
||||
|
|
@ -277,7 +277,7 @@ func CheckEnvVars(ctx *cli.Context, flags []cli.Flag, prefix string) {
|
|||
}
|
||||
}
|
||||
keyvals := os.Environ()
|
||||
sort.Strings(keyvals)
|
||||
slices.Sort(keyvals)
|
||||
|
||||
for _, keyval := range keyvals {
|
||||
key := strings.Split(keyval, "=")[0]
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ package jsre
|
|||
|
||||
import (
|
||||
"regexp"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
|
|
@ -88,6 +88,6 @@ func getCompletions(vm *goja.Runtime, line string) (results []string) {
|
|||
}
|
||||
}
|
||||
|
||||
sort.Strings(results)
|
||||
slices.Sort(results)
|
||||
return results
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -221,8 +221,8 @@ func (ctx ppctx) fields(obj *goja.Object) []string {
|
|||
}
|
||||
}
|
||||
iterOwnAndConstructorKeys(ctx.vm, obj, add)
|
||||
sort.Strings(vals)
|
||||
sort.Strings(methods)
|
||||
slices.Sort(vals)
|
||||
slices.Sort(methods)
|
||||
return append(vals, methods...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package prometheus
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ func (c *collector) writeGaugeInfo(name string, value metrics.GaugeInfoValue) {
|
|||
for k, v := range value {
|
||||
kvs = append(kvs, fmt.Sprintf("%v=%q", k, v))
|
||||
}
|
||||
sort.Strings(kvs)
|
||||
slices.Sort(kvs)
|
||||
c.buff.WriteString(fmt.Sprintf("{%v} 1\n\n", strings.Join(kvs, ", ")))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ package prometheus
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"slices"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
|
|
@ -34,7 +34,7 @@ func Handler(reg metrics.Registry) http.Handler {
|
|||
reg.Each(func(name string, i interface{}) {
|
||||
names = append(names, name)
|
||||
})
|
||||
sort.Strings(names)
|
||||
slices.Sort(names)
|
||||
|
||||
// Aggregate all the metrics into a Prometheus collector
|
||||
c := newCollector()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package metrics
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
|
@ -54,7 +54,7 @@ func (r *orderedRegistry) Each(f func(string, interface{})) {
|
|||
for name := range reg {
|
||||
names = append(names, name)
|
||||
}
|
||||
sort.Strings(names)
|
||||
slices.Sort(names)
|
||||
for _, name := range names {
|
||||
f(name, reg[name])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -182,7 +182,7 @@ func (h *httpServer) start() error {
|
|||
for path := range h.handlerNames {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
slices.Sort(paths)
|
||||
logged := make(map[string]bool, len(paths))
|
||||
for _, path := range paths {
|
||||
name := h.handlerNames[path]
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
"fmt"
|
||||
"go/format"
|
||||
"go/types"
|
||||
"sort"
|
||||
"slices"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rlp/internal/rlpstruct"
|
||||
"golang.org/x/tools/go/packages"
|
||||
|
|
@ -194,7 +194,7 @@ func (ctx *genContext) importsList() []string {
|
|||
imp = append(imp, fmt.Sprintf("%s %q", p.alias, path))
|
||||
}
|
||||
}
|
||||
sort.Strings(imp)
|
||||
slices.Sort(imp)
|
||||
return imp
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -417,7 +416,7 @@ func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes {
|
|||
deps := typedData.Dependencies(primaryType, []string{})
|
||||
if len(deps) > 0 {
|
||||
slicedDeps := deps[1:]
|
||||
sort.Strings(slicedDeps)
|
||||
slices.Sort(slicedDeps)
|
||||
deps = append([]string{primaryType}, slicedDeps...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ package tests
|
|||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sort"
|
||||
"slices"
|
||||
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
|
@ -740,7 +740,7 @@ func AvailableForks() []string {
|
|||
for k := range Forks {
|
||||
availableForks = append(availableForks, k)
|
||||
}
|
||||
sort.Strings(availableForks)
|
||||
slices.Sort(availableForks)
|
||||
return availableForks
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -269,7 +269,7 @@ func sortedMapKeys(m reflect.Value) []string {
|
|||
for i, k := range m.MapKeys() {
|
||||
keys[i] = k.String()
|
||||
}
|
||||
sort.Strings(keys)
|
||||
slices.Sort(keys)
|
||||
return keys
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"io"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -1309,7 +1310,7 @@ func printSet(set *trienode.NodeSet) string {
|
|||
for k := range set.Nodes {
|
||||
paths = append(paths, k)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
slices.Sort(paths)
|
||||
|
||||
for _, path := range paths {
|
||||
n := set.Nodes[path]
|
||||
|
|
|
|||
Loading…
Reference in a new issue