mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 13:47:19 +00:00
*: use slices.Concat where appropriate
Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
d5b7fc54e7
commit
357bc76882
6 changed files with 16 additions and 12 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"io"
|
||||
"math/big"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -133,8 +134,7 @@ func TestNEP17Transfer(t *testing.T) {
|
|||
}
|
||||
|
||||
t.Run("missing receiver", func(t *testing.T) {
|
||||
as := append([]string{}, args[:8]...)
|
||||
as = append(as, args[10:]...)
|
||||
as := slices.Concat(args[:8], args[10:])
|
||||
e.In.WriteString("one\r")
|
||||
e.RunWithErrorCheck(t, `Required flag "to" not set`, as...)
|
||||
e.In.Reset()
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
|
@ -61,7 +62,7 @@ func (s *Iterator) Value() stackitem.Item {
|
|||
}
|
||||
key := s.curr.Key
|
||||
if s.opts&FindRemovePrefix == 0 {
|
||||
key = append(bytes.Clone(s.prefix), key...)
|
||||
key = slices.Concat(s.prefix, key)
|
||||
}
|
||||
if s.opts&FindKeysOnly != 0 {
|
||||
return stackitem.NewByteArray(key)
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package mpt
|
||||
|
||||
import "github.com/nspcc-dev/neo-go/pkg/util"
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
)
|
||||
|
||||
// lcp returns the longest common prefix of a and b.
|
||||
// Note: it does no allocations.
|
||||
|
@ -85,9 +89,7 @@ func GetChildrenPaths(path []byte, node Node) map[util.Uint256][][]byte {
|
|||
}
|
||||
case *ExtensionNode:
|
||||
if n.next.Type() == HashT {
|
||||
cPath := make([]byte, len(path)+len(n.key))
|
||||
copy(cPath, path)
|
||||
copy(cPath[len(path):], n.key)
|
||||
cPath := slices.Concat(path, n.key)
|
||||
res[n.next.Hash()] = [][]byte{cPath}
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
|
@ -616,7 +617,7 @@ func (t *Trie) Find(prefix, from []byte, maxNum int) ([]storage.KeyValue, error)
|
|||
if leaf, ok := node.(*LeafNode); ok {
|
||||
if from == nil || !bytes.Equal(pathToNode, from) { // (*Billet).traverse includes `from` path into result if so. Need to filter out manually.
|
||||
res = append(res, storage.KeyValue{
|
||||
Key: append(bytes.Clone(prefix), pathToNode...),
|
||||
Key: slices.Concat(prefix, pathToNode),
|
||||
Value: bytes.Clone(leaf.value),
|
||||
})
|
||||
count++
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -98,7 +99,7 @@ func (m *TrieStore) Seek(rng storage.SeekRange, f func(k, v []byte) bool) {
|
|||
if leaf, ok := node.(*LeafNode); ok {
|
||||
// (*Billet).traverse includes `from` path into the result if so. It's OK for Seek, so shouldn't be filtered out.
|
||||
kv := storage.KeyValue{
|
||||
Key: append(bytes.Clone(rng.Prefix), pathToNode...), // Do not cut prefix.
|
||||
Key: slices.Concat(rng.Prefix, pathToNode), // Do not cut prefix.
|
||||
Value: bytes.Clone(leaf.value),
|
||||
}
|
||||
return !f(kv.Key, kv.Value) // Should return whether to stop.
|
||||
|
|
|
@ -3,6 +3,7 @@ package storage
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dboper"
|
||||
|
@ -105,10 +106,8 @@ type (
|
|||
func seekRangeToPrefixes(sr SeekRange) *util.Range {
|
||||
var (
|
||||
rang *util.Range
|
||||
start = make([]byte, len(sr.Prefix)+len(sr.Start))
|
||||
start = slices.Concat(sr.Prefix, sr.Start)
|
||||
)
|
||||
copy(start, sr.Prefix)
|
||||
copy(start[len(sr.Prefix):], sr.Start)
|
||||
|
||||
if !sr.Backwards {
|
||||
rang = util.BytesPrefix(sr.Prefix)
|
||||
|
|
Loading…
Reference in a new issue