Skip to content

Commit

Permalink
*: use slice.Concat where possible
Browse files Browse the repository at this point in the history
Closes #2738.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Sep 3, 2024
1 parent 9559cce commit f827018
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 37 deletions.
3 changes: 2 additions & 1 deletion pkg/morph/event/notary_preparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"slices"
"sync"

lru "github.com/hashicorp/golang-lru/v2"
Expand Down Expand Up @@ -85,7 +86,7 @@ func notaryPreparator(localAcc util.Uint160, alphaKeys client.AlphabetKeys, bc B
contractSysCall := make([]byte, 4)
binary.LittleEndian.PutUint32(contractSysCall, interopnames.ToID([]byte(interopnames.SystemContractCall)))

dummyInvocationScript := append([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64)...)
dummyInvocationScript := slices.Concat([]byte{byte(opcode.PUSHDATA1), 64}, make([]byte, 64))

const txCacheSize = 1000
cache, _ := lru.New[util.Uint256, struct{}](txCacheSize)
Expand Down
9 changes: 1 addition & 8 deletions pkg/services/object/put/distributed.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,7 @@ func (x placementIterator) iterateNodesForObject(obj oid.ID, f func(nodeDesc) er
return fmt.Errorf("sort container nodes for the object: %w", err)
}
if x.linearReplNum > 0 {
var n int
for i := range nodeLists {
n += len(nodeLists[i])
}
ns := make([]netmap.NodeInfo, 0, n)
for i := range nodeLists {
ns = append(ns, nodeLists[i]...)
}
ns := slices.Concat(nodeLists...)
nodeLists = [][]netmap.NodeInfo{ns}
replCounts = []uint{x.linearReplNum}
} else {
Expand Down
15 changes: 2 additions & 13 deletions pkg/services/object_manager/placement/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package placement
import (
"crypto/sha256"
"fmt"
"slices"
"sync"

"github.com/hashicorp/golang-lru/v2/simplelru"
Expand Down Expand Up @@ -99,17 +100,5 @@ func BuildObjectPlacement(nm *netmapSDK.NetMap, cnrNodes [][]netmapSDK.NodeInfo,

// FlattenNodes appends each row to the flat list.
func FlattenNodes(ns [][]netmapSDK.NodeInfo) []netmapSDK.NodeInfo {
var sz int

for i := range ns {
sz += len(ns[i])
}

result := make([]netmapSDK.NodeInfo, 0, sz)

for i := range ns {
result = append(result, ns[i]...)
}

return result
return slices.Concat(ns...)

Check warning on line 103 in pkg/services/object_manager/placement/netmap.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/object_manager/placement/netmap.go#L103

Added line #L103 was not covered by tests
}
13 changes: 2 additions & 11 deletions pkg/services/object_manager/placement/traverser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package placement
import (
"errors"
"fmt"
"slices"
"sync"

"github.com/nspcc-dev/neofs-node/pkg/network"
Expand Down Expand Up @@ -119,17 +120,7 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
}

func flatNodes(ns [][]netmap.NodeInfo) [][]netmap.NodeInfo {
sz := 0
for i := range ns {
sz += len(ns[i])
}

flat := make([]netmap.NodeInfo, 0, sz)
for i := range ns {
flat = append(flat, ns[i]...)
}

return [][]netmap.NodeInfo{flat}
return [][]netmap.NodeInfo{slices.Concat(ns...)}
}

// Node is a descriptor of storage node with information required for intra-container communication.
Expand Down
6 changes: 2 additions & 4 deletions pkg/services/tree/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"math"
"math/rand"
"slices"
"sync"

"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/pilorama"
Expand Down Expand Up @@ -365,10 +366,7 @@ func randomizeNodeOrder(cnrNodes []netmap.NodeInfo, pos int) []netmap.NodeInfo {
return nil
}

nodes := make([]netmap.NodeInfo, len(cnrNodes)-1)
n := copy(nodes, cnrNodes[:pos])
copy(nodes[n:], cnrNodes[pos+1:])

nodes := slices.Concat(cnrNodes[:pos], cnrNodes[pos+1:])

Check warning on line 369 in pkg/services/tree/sync.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/tree/sync.go#L369

Added line #L369 was not covered by tests
rand.Shuffle(len(nodes), func(i, j int) {
nodes[i], nodes[j] = nodes[j], nodes[i]
})
Expand Down

0 comments on commit f827018

Please sign in to comment.