[#376] container: Remove pointers from slices

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-02 11:18:59 +03:00 committed by Alex Vanin
parent aa1e092ca5
commit 30c530e83d
6 changed files with 39 additions and 57 deletions

View file

@ -39,7 +39,7 @@ func (a *Attribute) FromGRPCMessage(m grpc.Message) error {
return nil
}
func AttributesToGRPC(xs []*Attribute) (res []*container.Container_Attribute) {
func AttributesToGRPC(xs []Attribute) (res []*container.Container_Attribute) {
if xs != nil {
res = make([]*container.Container_Attribute, 0, len(xs))
@ -51,23 +51,17 @@ func AttributesToGRPC(xs []*Attribute) (res []*container.Container_Attribute) {
return
}
func AttributesFromGRPC(xs []*container.Container_Attribute) (res []*Attribute, err error) {
func AttributesFromGRPC(xs []*container.Container_Attribute) (res []Attribute, err error) {
if xs != nil {
res = make([]*Attribute, 0, len(xs))
res = make([]Attribute, len(xs))
for i := range xs {
var x *Attribute
if xs[i] != nil {
x = new(Attribute)
err = x.FromGRPCMessage(xs[i])
err = res[i].FromGRPCMessage(xs[i])
if err != nil {
return
}
}
res = append(res, x)
}
}
@ -1133,7 +1127,7 @@ func (a *UsedSpaceAnnouncement) FromGRPCMessage(m grpc.Message) error {
}
func UsedSpaceAnnouncementsToGRPCMessage(
ids []*UsedSpaceAnnouncement,
ids []UsedSpaceAnnouncement,
) (res []*container.AnnounceUsedSpaceRequest_Body_Announcement) {
if ids != nil {
res = make([]*container.AnnounceUsedSpaceRequest_Body_Announcement, 0, len(ids))
@ -1148,23 +1142,17 @@ func UsedSpaceAnnouncementsToGRPCMessage(
func UsedSpaceAnnouncementssFromGRPCMessage(
asV2 []*container.AnnounceUsedSpaceRequest_Body_Announcement,
) (res []*UsedSpaceAnnouncement, err error) {
) (res []UsedSpaceAnnouncement, err error) {
if asV2 != nil {
res = make([]*UsedSpaceAnnouncement, 0, len(asV2))
res = make([]UsedSpaceAnnouncement, len(asV2))
for i := range asV2 {
var a *UsedSpaceAnnouncement
if asV2[i] != nil {
a = new(UsedSpaceAnnouncement)
err = a.FromGRPCMessage(asV2[i])
err = res[i].FromGRPCMessage(asV2[i])
if err != nil {
return
}
}
res = append(res, a)
}
}

View file

@ -138,7 +138,7 @@ func (c *Container) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range c.attr {
n, err = protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], c.attr[i])
n, err = protoutil.NestedStructureMarshal(containerAttributesField, buf[offset:], &c.attr[i])
if err != nil {
return nil, err
}
@ -165,7 +165,7 @@ func (c *Container) StableSize() (size int) {
size += protoutil.UInt32Size(containerBasicACLField, c.basicACL)
for i := range c.attr {
size += protoutil.NestedStructureSize(containerAttributesField, c.attr[i])
size += protoutil.NestedStructureSize(containerAttributesField, &c.attr[i])
}
size += protoutil.NestedStructureSize(containerPlacementField, c.policy)
@ -432,7 +432,7 @@ func (r *ListResponseBody) StableMarshal(buf []byte) ([]byte, error) {
)
for i := range r.cidList {
n, err = protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], r.cidList[i])
n, err = protoutil.NestedStructureMarshal(listRespBodyIDsField, buf[offset:], &r.cidList[i])
if err != nil {
return nil, err
}
@ -449,7 +449,7 @@ func (r *ListResponseBody) StableSize() (size int) {
}
for i := range r.cidList {
size += protoutil.NestedStructureSize(listRespBodyIDsField, r.cidList[i])
size += protoutil.NestedStructureSize(listRespBodyIDsField, &r.cidList[i])
}
return size
@ -665,7 +665,7 @@ func (r *AnnounceUsedSpaceRequestBody) StableMarshal(buf []byte) ([]byte, error)
)
for i := range r.announcements {
n, err = protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], r.announcements[i])
n, err = protoutil.NestedStructureMarshal(usedSpaceReqBodyAnnouncementsField, buf[offset:], &r.announcements[i])
if err != nil {
return nil, err
}
@ -682,7 +682,7 @@ func (r *AnnounceUsedSpaceRequestBody) StableSize() (size int) {
}
for i := range r.announcements {
size += protoutil.NestedStructureSize(usedSpaceReqBodyAnnouncementsField, r.announcements[i])
size += protoutil.NestedStructureSize(usedSpaceReqBodyAnnouncementsField, &r.announcements[i])
}
return size

View file

@ -19,13 +19,13 @@ func GenerateAttribute(empty bool) *container.Attribute {
return m
}
func GenerateAttributes(empty bool) []*container.Attribute {
var res []*container.Attribute
func GenerateAttributes(empty bool) []container.Attribute {
var res []container.Attribute
if !empty {
res = append(res,
GenerateAttribute(false),
GenerateAttribute(false),
*GenerateAttribute(false),
*GenerateAttribute(false),
)
}
@ -340,13 +340,13 @@ func GenerateUsedSpaceAnnouncement(empty bool) *container.UsedSpaceAnnouncement
return m
}
func GenerateUsedSpaceAnnouncements(empty bool) []*container.UsedSpaceAnnouncement {
var res []*container.UsedSpaceAnnouncement
func GenerateUsedSpaceAnnouncements(empty bool) []container.UsedSpaceAnnouncement {
var res []container.UsedSpaceAnnouncement
if !empty {
res = append(res,
GenerateUsedSpaceAnnouncement(false),
GenerateUsedSpaceAnnouncement(false),
*GenerateUsedSpaceAnnouncement(false),
*GenerateUsedSpaceAnnouncement(false),
)
}

View file

@ -20,7 +20,7 @@ type Container struct {
basicACL uint32
attr []*Attribute
attr []Attribute
policy *netmap.PlacementPolicy
}
@ -101,7 +101,7 @@ type ListRequest struct {
}
type ListResponseBody struct {
cidList []*refs.ContainerID
cidList []refs.ContainerID
}
type ListResponse struct {
@ -163,7 +163,7 @@ type UsedSpaceAnnouncement struct {
}
type AnnounceUsedSpaceRequestBody struct {
announcements []*UsedSpaceAnnouncement
announcements []UsedSpaceAnnouncement
}
type AnnounceUsedSpaceRequest struct {
@ -264,7 +264,7 @@ func (c *Container) SetBasicACL(v uint32) {
}
}
func (c *Container) GetAttributes() []*Attribute {
func (c *Container) GetAttributes() []Attribute {
if c != nil {
return c.attr
}
@ -272,7 +272,7 @@ func (c *Container) GetAttributes() []*Attribute {
return nil
}
func (c *Container) SetAttributes(v []*Attribute) {
func (c *Container) SetAttributes(v []Attribute) {
if c != nil {
c.attr = v
}
@ -542,7 +542,7 @@ func (r *ListRequest) SetBody(v *ListRequestBody) {
}
}
func (r *ListResponseBody) GetContainerIDs() []*refs.ContainerID {
func (r *ListResponseBody) GetContainerIDs() []refs.ContainerID {
if r != nil {
return r.cidList
}
@ -550,7 +550,7 @@ func (r *ListResponseBody) GetContainerIDs() []*refs.ContainerID {
return nil
}
func (r *ListResponseBody) SetContainerIDs(v []*refs.ContainerID) {
func (r *ListResponseBody) SetContainerIDs(v []refs.ContainerID) {
if r != nil {
r.cidList = v
}
@ -760,7 +760,7 @@ func (a *UsedSpaceAnnouncement) SetContainerID(v *refs.ContainerID) {
}
}
func (r *AnnounceUsedSpaceRequestBody) GetAnnouncements() []*UsedSpaceAnnouncement {
func (r *AnnounceUsedSpaceRequestBody) GetAnnouncements() []UsedSpaceAnnouncement {
if r != nil {
return r.announcements
}
@ -768,7 +768,7 @@ func (r *AnnounceUsedSpaceRequestBody) GetAnnouncements() []*UsedSpaceAnnounceme
return nil
}
func (r *AnnounceUsedSpaceRequestBody) SetAnnouncements(v []*UsedSpaceAnnouncement) {
func (r *AnnounceUsedSpaceRequestBody) SetAnnouncements(v []UsedSpaceAnnouncement) {
if r != nil {
r.announcements = v
}

View file

@ -52,7 +52,7 @@ func (c *ContainerID) FromGRPCMessage(m grpc.Message) error {
return nil
}
func ContainerIDsToGRPCMessage(ids []*ContainerID) (res []*refs.ContainerID) {
func ContainerIDsToGRPCMessage(ids []ContainerID) (res []*refs.ContainerID) {
if ids != nil {
res = make([]*refs.ContainerID, 0, len(ids))
@ -64,23 +64,17 @@ func ContainerIDsToGRPCMessage(ids []*ContainerID) (res []*refs.ContainerID) {
return
}
func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []*ContainerID, err error) {
func ContainerIDsFromGRPCMessage(idsV2 []*refs.ContainerID) (res []ContainerID, err error) {
if idsV2 != nil {
res = make([]*ContainerID, 0, len(idsV2))
res = make([]ContainerID, len(idsV2))
for i := range idsV2 {
var id *ContainerID
if idsV2[i] != nil {
id = new(ContainerID)
err = id.FromGRPCMessage(idsV2[i])
err = res[i].FromGRPCMessage(idsV2[i])
if err != nil {
return
}
}
res = append(res, id)
}
}

View file

@ -71,13 +71,13 @@ func GenerateContainerID(empty bool) *refs.ContainerID {
return m
}
func GenerateContainerIDs(empty bool) []*refs.ContainerID {
var res []*refs.ContainerID
func GenerateContainerIDs(empty bool) []refs.ContainerID {
var res []refs.ContainerID
if !empty {
res = append(res,
GenerateContainerID(false),
GenerateContainerID(false),
*GenerateContainerID(false),
*GenerateContainerID(false),
)
}