mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
*: use slices.Sort() where appropriate
It's always faster for simple types. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
d40ccb3e57
commit
de665b5567
8 changed files with 21 additions and 21 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -362,7 +362,7 @@ func CompileAndSave(src string, o *Options) ([]byte, error) {
|
|||
for k := range di.EmittedEvents {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
slices.Sort(keys)
|
||||
for _, eventName := range keys {
|
||||
var (
|
||||
eventUsages = di.EmittedEvents[eventName]
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"go/ast"
|
||||
"go/types"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
@ -210,7 +210,7 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
|
|||
}
|
||||
fnames = append(fnames, name)
|
||||
}
|
||||
sort.Strings(fnames)
|
||||
slices.Sort(fnames)
|
||||
d.NamedTypes = make(map[string]binding.ExtendedType)
|
||||
for _, name := range fnames {
|
||||
m := c.methodInfoFromScope(name, c.funcs[name], d.NamedTypes)
|
||||
|
|
|
@ -3,7 +3,6 @@ package config
|
|||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -41,8 +40,8 @@ func (a *ApplicationConfiguration) EqualsButServices(o *ApplicationConfiguration
|
|||
}
|
||||
aCp := slices.Clone(a.P2P.Addresses)
|
||||
oCp := slices.Clone(o.P2P.Addresses)
|
||||
sort.Strings(aCp)
|
||||
sort.Strings(oCp)
|
||||
slices.Sort(aCp)
|
||||
slices.Sort(oCp)
|
||||
if !slices.Equal(aCp, oCp) {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package network
|
|||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"sort"
|
||||
"slices"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -91,7 +91,7 @@ func TestDefaultDiscoverer(t *testing.T) {
|
|||
|
||||
tryMaxWait = 1 // Don't waste time.
|
||||
var set1 = []string{"1.1.1.1:10333", "2.2.2.2:10333"}
|
||||
sort.Strings(set1)
|
||||
slices.Sort(set1)
|
||||
|
||||
// Added addresses should end up in the pool and in the unconnected set.
|
||||
// Done twice to check re-adding unconnected addresses, which should be
|
||||
|
@ -100,7 +100,7 @@ func TestDefaultDiscoverer(t *testing.T) {
|
|||
d.BackFill(set1...)
|
||||
assert.Equal(t, len(set1), d.PoolCount())
|
||||
set1D := d.UnconnectedPeers()
|
||||
sort.Strings(set1D)
|
||||
slices.Sort(set1D)
|
||||
assert.Equal(t, 0, len(d.GoodPeers()))
|
||||
assert.Equal(t, 0, len(d.BadPeers()))
|
||||
require.Equal(t, set1, set1D)
|
||||
|
@ -120,7 +120,7 @@ func TestDefaultDiscoverer(t *testing.T) {
|
|||
}
|
||||
}
|
||||
require.Eventually(t, func() bool { return len(d.UnconnectedPeers()) == 0 }, 2*time.Second, 50*time.Millisecond)
|
||||
sort.Strings(dialled)
|
||||
slices.Sort(dialled)
|
||||
assert.Equal(t, 0, d.PoolCount())
|
||||
assert.Equal(t, 0, len(d.BadPeers()))
|
||||
assert.Equal(t, 0, len(d.GoodPeers()))
|
||||
|
@ -150,7 +150,7 @@ func TestDefaultDiscoverer(t *testing.T) {
|
|||
}, addr.Capabilities)
|
||||
gAddrs[i] = addr.Address
|
||||
}
|
||||
sort.Strings(gAddrs)
|
||||
slices.Sort(gAddrs)
|
||||
assert.Equal(t, 0, d.PoolCount())
|
||||
assert.Equal(t, 0, len(d.UnconnectedPeers()))
|
||||
assert.Equal(t, 0, len(d.BadPeers()))
|
||||
|
@ -176,7 +176,7 @@ func TestDefaultDiscoverer(t *testing.T) {
|
|||
ts.retFalse.Store(1)
|
||||
assert.Equal(t, len(set1), d.PoolCount())
|
||||
set1D := d.UnconnectedPeers()
|
||||
sort.Strings(set1D)
|
||||
slices.Sort(set1D)
|
||||
assert.Equal(t, 0, len(d.BadPeers()))
|
||||
require.Equal(t, set1, set1D)
|
||||
|
||||
|
@ -193,7 +193,7 @@ func TestDefaultDiscoverer(t *testing.T) {
|
|||
}
|
||||
}
|
||||
require.Eventually(t, func() bool { return d.PoolCount() == 0 }, 2*time.Second, 50*time.Millisecond)
|
||||
sort.Strings(dialledBad)
|
||||
slices.Sort(dialledBad)
|
||||
for i := 0; i < len(set1); i++ {
|
||||
for j := 0; j < connRetries; j++ {
|
||||
assert.Equal(t, set1[i], dialledBad[i*connRetries+j])
|
||||
|
@ -216,7 +216,7 @@ func TestSeedDiscovery(t *testing.T) {
|
|||
ts := &fakeTransp{}
|
||||
ts.dialCh = make(chan string)
|
||||
ts.retFalse.Store(1) // Fail all dial requests.
|
||||
sort.Strings(seeds)
|
||||
slices.Sort(seeds)
|
||||
|
||||
d := NewDefaultDiscovery(seeds, time.Second/10, ts)
|
||||
tryMaxWait = 1 // Don't waste time.
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -866,7 +866,7 @@ func TestWSConcurrentAccess(t *testing.T) {
|
|||
}
|
||||
ids.lock.RUnlock()
|
||||
|
||||
sort.Ints(idsList)
|
||||
slices.Sort(idsList)
|
||||
require.Equal(t, 1, idsList[0])
|
||||
require.Less(t, idsList[len(idsList)-1],
|
||||
batchCount*3+1) // batchCount*requestsPerBatch+1
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"go/format"
|
||||
"go/token"
|
||||
"io"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
@ -159,7 +159,7 @@ func Generate(cfg Config) error {
|
|||
if ctr.Hash != "" {
|
||||
ctr.Imports = append(ctr.Imports, "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal")
|
||||
}
|
||||
sort.Strings(ctr.Imports)
|
||||
slices.Sort(ctr.Imports)
|
||||
|
||||
return FExecute(srcTemplate, cfg.Output, ctr)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package manifest
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -94,7 +95,7 @@ func (p Parameters) AreValid() error {
|
|||
|
||||
// stringsHaveDups checks the given set of strings for duplicates. It modifies the slice given!
|
||||
func stringsHaveDups(strings []string) bool {
|
||||
sort.Strings(strings)
|
||||
slices.Sort(strings)
|
||||
for i := range strings {
|
||||
if i == 0 {
|
||||
continue
|
||||
|
|
|
@ -848,7 +848,7 @@ func scTemplateToRPC(cfg binding.Config, ctr ContractTmpl, imports map[string]st
|
|||
for imp := range imports {
|
||||
ctr.Imports = append(ctr.Imports, imp)
|
||||
}
|
||||
sort.Strings(ctr.Imports)
|
||||
slices.Sort(ctr.Imports)
|
||||
return ctr
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue