From 63cdc16088cb17b11659723c5d68f11218f09608 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 17 May 2022 16:44:35 +0300 Subject: [PATCH] [#1386] eacl/v2: Do not allocate intermediate slices for XHeaders Signed-off-by: Evgenii Stratonikov --- pkg/services/object/acl/eacl/v2/xheader.go | 31 +++++++--------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/pkg/services/object/acl/eacl/v2/xheader.go b/pkg/services/object/acl/eacl/v2/xheader.go index d25a25f8b..cda629b20 100644 --- a/pkg/services/object/acl/eacl/v2/xheader.go +++ b/pkg/services/object/acl/eacl/v2/xheader.go @@ -1,7 +1,6 @@ package v2 import ( - "github.com/nspcc-dev/neofs-api-go/v2/session" eaclSDK "github.com/nspcc-dev/neofs-sdk-go/eacl" sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" ) @@ -22,21 +21,16 @@ type responseXHeaderSource struct { func (s requestXHeaderSource) GetXHeaders() []eaclSDK.Header { ln := 0 - xHdrs := make([][]session.XHeader, 0) for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() { - x := meta.GetXHeaders() - - ln += len(x) - - xHdrs = append(xHdrs, x) + ln += len(meta.GetXHeaders()) } res := make([]eaclSDK.Header, 0, ln) - - for i := range xHdrs { - for j := range xHdrs[i] { - res = append(res, sessionSDK.NewXHeaderFromV2(&xHdrs[i][j])) + for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() { + x := meta.GetXHeaders() + for i := range x { + res = append(res, sessionSDK.NewXHeaderFromV2(&x[i])) } } @@ -45,21 +39,16 @@ func (s requestXHeaderSource) GetXHeaders() []eaclSDK.Header { func (s responseXHeaderSource) GetXHeaders() []eaclSDK.Header { ln := 0 - xHdrs := make([][]session.XHeader, 0) for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() { - x := meta.GetXHeaders() - - ln += len(x) - - xHdrs = append(xHdrs, x) + ln += len(meta.GetXHeaders()) } res := make([]eaclSDK.Header, 0, ln) - - for i := range xHdrs { - for j := range xHdrs[i] { - res = append(res, sessionSDK.NewXHeaderFromV2(&xHdrs[i][j])) + for meta := s.req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() { + x := meta.GetXHeaders() + for i := range x { + res = append(res, sessionSDK.NewXHeaderFromV2(&x[i])) } }