diff --git a/cmd/neofs-cli/internal/client/client.go b/cmd/neofs-cli/internal/client/client.go index 10d6bc3b7..ffeb7a033 100644 --- a/cmd/neofs-cli/internal/client/client.go +++ b/cmd/neofs-cli/internal/client/client.go @@ -56,7 +56,7 @@ type ListContainersRes struct { } // IDList returns list of identifiers of user's containers. -func (x ListContainersRes) IDList() []*cid.ID { +func (x ListContainersRes) IDList() []cid.ID { return x.cliRes.Containers() } diff --git a/cmd/neofs-cli/modules/acl/extended/create_test.go b/cmd/neofs-cli/modules/acl/extended/create_test.go index 88da39533..193504403 100644 --- a/cmd/neofs-cli/modules/acl/extended/create_test.go +++ b/cmd/neofs-cli/modules/acl/extended/create_test.go @@ -74,7 +74,7 @@ func TestParseTable(t *testing.T) { actualRecord := eaclTable.Records()[len(eaclTable.Records())-1] - equalRecords(t, expectedRecord, actualRecord) + equalRecords(t, expectedRecord, &actualRecord) } }) } diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 381521295..5007f212c 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -600,9 +600,9 @@ func getSessionToken(path string) (*session.Token, error) { return tok, nil } -func prettyPrintContainerList(cmd *cobra.Command, list []*cid.ID) { +func prettyPrintContainerList(cmd *cobra.Command, list []cid.ID) { for i := range list { - cmd.Println(list[i]) + cmd.Println(&list[i]) // stringer defined on pointer } } @@ -644,8 +644,8 @@ func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error) return nil, errors.New("can't parse placement policy") } -func parseAttributes(attributes []string) ([]*container.Attribute, error) { - result := make([]*container.Attribute, 0, len(attributes)+2) // name + timestamp attributes +func parseAttributes(attributes []string) ([]container.Attribute, error) { + result := make([]container.Attribute, len(attributes), len(attributes)+2) // name + timestamp attributes for i := range attributes { kvPair := strings.Split(attributes[i], attributeDelimiter) @@ -653,27 +653,22 @@ func parseAttributes(attributes []string) ([]*container.Attribute, error) { return nil, errors.New("invalid container attribute") } - parsedAttribute := container.NewAttribute() - parsedAttribute.SetKey(kvPair[0]) - parsedAttribute.SetValue(kvPair[1]) - - result = append(result, parsedAttribute) + result[i].SetKey(kvPair[0]) + result[i].SetValue(kvPair[1]) } if !containerNoTimestamp { - timestamp := container.NewAttribute() - timestamp.SetKey(container.AttributeTimestamp) - timestamp.SetValue(strconv.FormatInt(time.Now().Unix(), 10)) - - result = append(result, timestamp) + index := len(result) + result = append(result, container.Attribute{}) + result[index].SetKey(container.AttributeTimestamp) + result[index].SetValue(strconv.FormatInt(time.Now().Unix(), 10)) } if containerName != "" { - cnrName := container.NewAttribute() - cnrName.SetKey(container.AttributeName) - cnrName.SetValue(containerName) - - result = append(result, cnrName) + index := len(result) + result = append(result, container.Attribute{}) + result[index].SetKey(container.AttributeName) + result[index].SetValue(containerName) } return result, nil diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 9fe893faf..1d0eb85ef 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -414,22 +414,24 @@ func putObject(cmd *cobra.Command, _ []string) { expiresOn, _ := cmd.Flags().GetUint64(putExpiresOnFlag) if expiresOn > 0 { - var expAttr *object.Attribute + var expAttrFound bool + expAttrValue := strconv.FormatUint(expiresOn, 10) - for _, a := range attrs { - if a.Key() == objectV2.SysAttributeExpEpoch { - expAttr = a + for i := range attrs { + if attrs[i].Key() == objectV2.SysAttributeExpEpoch { + attrs[i].SetValue(expAttrValue) + expAttrFound = true break } } - if expAttr == nil { - expAttr = object.NewAttribute() - expAttr.SetKey(objectV2.SysAttributeExpEpoch) - attrs = append(attrs, expAttr) + if !expAttrFound { + index := len(attrs) + attrs = append(attrs, object.Attribute{}) + attrs[index].SetKey(objectV2.SysAttributeExpEpoch) + attrs[index].SetValue(expAttrValue) } - expAttr.SetValue(strconv.FormatUint(expiresOn, 10)) } obj := object.New() @@ -719,7 +721,7 @@ func parseSearchFilters(cmd *cobra.Command) (object.SearchFilters, error) { return fs, nil } -func parseObjectAttrs(cmd *cobra.Command) ([]*object.Attribute, error) { +func parseObjectAttrs(cmd *cobra.Command) ([]object.Attribute, error) { var rawAttrs []string raw := cmd.Flag("attributes").Value.String() @@ -727,33 +729,31 @@ func parseObjectAttrs(cmd *cobra.Command) ([]*object.Attribute, error) { rawAttrs = strings.Split(raw, ",") } - attrs := make([]*object.Attribute, 0, len(rawAttrs)+2) // name + timestamp attributes + attrs := make([]object.Attribute, len(rawAttrs), len(rawAttrs)+2) // name + timestamp attributes for i := range rawAttrs { kv := strings.SplitN(rawAttrs[i], "=", 2) if len(kv) != 2 { return nil, fmt.Errorf("invalid attribute format: %s", rawAttrs[i]) } - attr := object.NewAttribute() - attr.SetKey(kv[0]) - attr.SetValue(kv[1]) - attrs = append(attrs, attr) + attrs[i].SetKey(kv[0]) + attrs[i].SetValue(kv[1]) } disableFilename, _ := cmd.Flags().GetBool("disable-filename") if !disableFilename { filename := filepath.Base(cmd.Flag("file").Value.String()) - attr := object.NewAttribute() - attr.SetKey(object.AttributeFileName) - attr.SetValue(filename) - attrs = append(attrs, attr) + index := len(attrs) + attrs = append(attrs, object.Attribute{}) + attrs[index].SetKey(object.AttributeFileName) + attrs[index].SetValue(filename) } disableTime, _ := cmd.Flags().GetBool("disable-timestamp") if !disableTime { - attr := object.NewAttribute() - attr.SetKey(object.AttributeTimestamp) - attr.SetValue(strconv.FormatInt(time.Now().Unix(), 10)) - attrs = append(attrs, attr) + index := len(attrs) + attrs = append(attrs, object.Attribute{}) + attrs[index].SetKey(object.AttributeTimestamp) + attrs[index].SetValue(strconv.FormatInt(time.Now().Unix(), 10)) } return attrs, nil @@ -894,7 +894,7 @@ func printSplitHeader(cmd *cobra.Command, obj *object.Object) error { } for _, child := range obj.Children() { - cmd.Printf("Split ChildID: %s\n", child) + cmd.Printf("Split ChildID: %s\n", &child) // stringer defined on pointer } if signature := obj.Signature(); signature != nil { diff --git a/cmd/neofs-cli/modules/storagegroup.go b/cmd/neofs-cli/modules/storagegroup.go index 37a0ab9f2..7ff676e5e 100644 --- a/cmd/neofs-cli/modules/storagegroup.go +++ b/cmd/neofs-cli/modules/storagegroup.go @@ -170,15 +170,11 @@ func putSG(cmd *cobra.Command, _ []string) { cid, err := getCID(cmd) exitOnErr(cmd, err) - members := make([]*oidSDK.ID, 0, len(sgMembers)) + members := make([]oidSDK.ID, len(sgMembers)) for i := range sgMembers { - id := oidSDK.NewID() - - err = id.Parse(sgMembers[i]) + err = members[i].Parse(sgMembers[i]) exitOnErr(cmd, errf("could not parse object ID: %w", err)) - - members = append(members, id) } var ( @@ -265,7 +261,7 @@ func getSG(cmd *cobra.Command, _ []string) { cmd.Println("Members:") for i := range members { - cmd.Printf("\t%s\n", members[i]) + cmd.Printf("\t%s\n", &members[i]) // stringer defined on pointer } } } diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index 80a258561..0eacbb545 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -180,14 +180,10 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error { idList := tombstone.Members() addrList := make([]*addressSDK.Address, 0, len(idList)) - for _, id := range idList { - if id == nil { - return fmt.Errorf("(%T) empty member in tombstone", v) - } - + for i := range idList { a := addressSDK.NewAddress() a.SetContainerID(cid) - a.SetObjectID(id) + a.SetObjectID(&idList[i]) addrList = append(addrList, a) } @@ -208,12 +204,6 @@ func (v *FormatValidator) ValidateContent(o *object.Object) error { if err := sg.Unmarshal(o.Payload()); err != nil { return fmt.Errorf("(%T) could not unmarshal SG content: %w", v, err) } - - for _, id := range sg.Members() { - if id == nil { - return fmt.Errorf("(%T) empty member in SG", v) - } - } case object.TypeLock: if len(o.Payload()) == 0 { return errors.New("empty payload in lock") diff --git a/pkg/local_object_storage/shard/control.go b/pkg/local_object_storage/shard/control.go index e6cfe4f35..732b5aee4 100644 --- a/pkg/local_object_storage/shard/control.go +++ b/pkg/local_object_storage/shard/control.go @@ -94,14 +94,10 @@ func (s *Shard) refillMetabase() error { memberIDs := tombstone.Members() tombMembers := make([]*addressSDK.Address, 0, len(memberIDs)) - for _, id := range memberIDs { - if id == nil { - return errors.New("empty member in tombstone") - } - + for i := range memberIDs { a := addressSDK.NewAddress() a.SetContainerID(cid) - a.SetObjectID(id) + a.SetObjectID(&memberIDs[i]) tombMembers = append(tombMembers, a) } diff --git a/pkg/services/control/server/netmap_snapshot.go b/pkg/services/control/server/netmap_snapshot.go index 5dda08214..29b31a5d6 100644 --- a/pkg/services/control/server/netmap_snapshot.go +++ b/pkg/services/control/server/netmap_snapshot.go @@ -79,7 +79,7 @@ func stateFromAPI(s netmapAPI.NodeState) control.NetmapStatus { } } -func attributesFromAPI(apiAttrs []*netmapAPI.NodeAttribute) []*control.NodeInfo_Attribute { +func attributesFromAPI(apiAttrs []netmapAPI.NodeAttribute) []*control.NodeInfo_Attribute { attrs := make([]*control.NodeInfo_Attribute, 0, len(apiAttrs)) for _, apiAttr := range apiAttrs { diff --git a/pkg/services/object/util/chain.go b/pkg/services/object/util/chain.go index e4de91d86..f5b659b61 100644 --- a/pkg/services/object/util/chain.go +++ b/pkg/services/object/util/chain.go @@ -95,7 +95,7 @@ func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberH addr.SetContainerID(cid) addr.SetObjectID(res.Link()) - chain := make([]*oidSDK.ID, 0) + chain := make([]oidSDK.ID, 0) if _, err := traverseSplitChain(r, addr, func(member *object.Object, reverseDirection bool) (stop bool) { children := member.Children() @@ -114,7 +114,7 @@ func traverseSplitChain(r HeadReceiver, addr *addressSDK.Address, h SplitMemberH var reverseChain []*object.Object for i := range chain { - addr.SetObjectID(chain[i]) + addr.SetObjectID(&chain[i]) if stop, err := traverseSplitChain(r, addr, func(member *object.Object, reverseDirection bool) (stop bool) { if !reverseDirection { diff --git a/pkg/services/object/util/prm.go b/pkg/services/object/util/prm.go index 37f7635d3..4ad96d9a5 100644 --- a/pkg/services/object/util/prm.go +++ b/pkg/services/object/util/prm.go @@ -136,7 +136,7 @@ func CommonPrmFromV2(req interface { return nil, err } default: - xhdr := sessionsdk.NewXHeaderFromV2(xHdrs[i]) + xhdr := sessionsdk.NewXHeaderFromV2(&xHdrs[i]) prm.xhdrs = append(prm.xhdrs, xhdr) } diff --git a/pkg/services/object_manager/storagegroup/collect.go b/pkg/services/object_manager/storagegroup/collect.go index 84745ecec..eff3eaa0d 100644 --- a/pkg/services/object_manager/storagegroup/collect.go +++ b/pkg/services/object_manager/storagegroup/collect.go @@ -15,10 +15,10 @@ import ( // with information about members collected via HeadReceiver. // // Resulting storage group consists of physically stored objects only. -func CollectMembers(r objutil.HeadReceiver, cid *cid.ID, members []*oidSDK.ID) (*storagegroup.StorageGroup, error) { +func CollectMembers(r objutil.HeadReceiver, cid *cid.ID, members []oidSDK.ID) (*storagegroup.StorageGroup, error) { var ( sumPhySize uint64 - phyMembers []*oidSDK.ID + phyMembers []oidSDK.ID phyHashes [][]byte addr = addressSDK.NewAddress() sg = storagegroup.New() @@ -27,10 +27,10 @@ func CollectMembers(r objutil.HeadReceiver, cid *cid.ID, members []*oidSDK.ID) ( addr.SetContainerID(cid) for i := range members { - addr.SetObjectID(members[i]) + addr.SetObjectID(&members[i]) if err := objutil.IterateAllSplitLeaves(r, addr, func(leaf *object.Object) { - phyMembers = append(phyMembers, leaf.ID()) + phyMembers = append(phyMembers, *leaf.ID()) sumPhySize += leaf.PayloadSize() phyHashes = append(phyHashes, leaf.PayloadHomomorphicHash().Sum()) }); err != nil {