[#263] pkg/netmap: Do not allocate nil repeated fields during conversion

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-12 15:58:37 +03:00 committed by Alex Vanin
parent 1031f3122e
commit 5a9dd7ab3f
2 changed files with 22 additions and 12 deletions

View file

@ -230,14 +230,16 @@ func (f *Filter) InnerFilters() []*Filter {
)
}
func filtersToV2(fs []*Filter) []*netmap.Filter {
fsV2 := make([]*netmap.Filter, 0, len(fs))
func filtersToV2(fs []*Filter) (fsV2 []*netmap.Filter) {
if fs != nil {
fsV2 = make([]*netmap.Filter, 0, len(fs))
for i := range fs {
fsV2 = append(fsV2, fs[i].ToV2())
}
}
return fsV2
return
}
// SetInnerFilters sets list of inner filters.

View file

@ -38,11 +38,15 @@ func (p *PlacementPolicy) Replicas() []*Replica {
// SetReplicas sets list of object replica descriptors.
func (p *PlacementPolicy) SetReplicas(rs ...*Replica) {
rsV2 := make([]*netmap.Replica, 0, len(rs))
var rsV2 []*netmap.Replica
if rs != nil {
rsV2 = make([]*netmap.Replica, 0, len(rs))
for i := range rs {
rsV2 = append(rsV2, rs[i].ToV2())
}
}
(*netmap.PlacementPolicy)(p).
SetReplicas(rsV2)
@ -76,14 +80,18 @@ func (p *PlacementPolicy) Selectors() []*Selector {
// SetSelectors sets set of selectors to form the container's nodes subset.
func (p *PlacementPolicy) SetSelectors(ss ...*Selector) {
rsV2 := make([]*netmap.Selector, 0, len(ss))
var ssV2 []*netmap.Selector
if ss != nil {
ssV2 = make([]*netmap.Selector, 0, len(ss))
for i := range ss {
rsV2 = append(rsV2, ss[i].ToV2())
ssV2 = append(ssV2, ss[i].ToV2())
}
}
(*netmap.PlacementPolicy)(p).
SetSelectors(rsV2)
SetSelectors(ssV2)
}
// Filters returns list of named filters to reference in selectors.