[#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 { func filtersToV2(fs []*Filter) (fsV2 []*netmap.Filter) {
fsV2 := make([]*netmap.Filter, 0, len(fs)) if fs != nil {
fsV2 = make([]*netmap.Filter, 0, len(fs))
for i := range fs { for i := range fs {
fsV2 = append(fsV2, fs[i].ToV2()) fsV2 = append(fsV2, fs[i].ToV2())
}
} }
return fsV2 return
} }
// SetInnerFilters sets list of inner filters. // SetInnerFilters sets list of inner filters.

View file

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