From 915f87959ec245ad14318ff8772afb7c12fe1cde Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 17 May 2022 16:40:25 +0300 Subject: [PATCH] [#1386] eacl/v2: Allocate []eaclSDK.Header slice immediately There is no point in having intermediate `[]sessionSDK.XHeader`. Signed-off-by: Evgenii Stratonikov --- pkg/services/object/acl/eacl/v2/headers.go | 11 +---------- pkg/services/object/acl/eacl/v2/xheader.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/pkg/services/object/acl/eacl/v2/headers.go b/pkg/services/object/acl/eacl/v2/headers.go index 9c3dd27a3..ea8408ae5 100644 --- a/pkg/services/object/acl/eacl/v2/headers.go +++ b/pkg/services/object/acl/eacl/v2/headers.go @@ -14,7 +14,6 @@ import ( objectSDKAddress "github.com/nspcc-dev/neofs-sdk-go/object/address" objectSDKID "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" - sessionSDK "github.com/nspcc-dev/neofs-sdk-go/session" ) type Option func(*cfg) @@ -84,15 +83,7 @@ func (h headerSource) HeadersOfType(typ eaclSDK.FilterHeaderType) ([]eaclSDK.Hea } func requestHeaders(msg xHeaderSource) []eaclSDK.Header { - xHdrs := msg.GetXHeaders() - - res := make([]eaclSDK.Header, 0, len(xHdrs)) - - for i := range xHdrs { - res = append(res, sessionSDK.NewXHeaderFromV2(&xHdrs[i])) - } - - return res + return msg.GetXHeaders() } func (h *cfg) objectHeaders() ([]eaclSDK.Header, error) { diff --git a/pkg/services/object/acl/eacl/v2/xheader.go b/pkg/services/object/acl/eacl/v2/xheader.go index 62364e818..d25a25f8b 100644 --- a/pkg/services/object/acl/eacl/v2/xheader.go +++ b/pkg/services/object/acl/eacl/v2/xheader.go @@ -2,10 +2,12 @@ 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" ) type xHeaderSource interface { - GetXHeaders() []session.XHeader + GetXHeaders() []eaclSDK.Header } type requestXHeaderSource struct { @@ -18,7 +20,7 @@ type responseXHeaderSource struct { req Request } -func (s requestXHeaderSource) GetXHeaders() []session.XHeader { +func (s requestXHeaderSource) GetXHeaders() []eaclSDK.Header { ln := 0 xHdrs := make([][]session.XHeader, 0) @@ -30,18 +32,18 @@ func (s requestXHeaderSource) GetXHeaders() []session.XHeader { xHdrs = append(xHdrs, x) } - res := make([]session.XHeader, 0, ln) + res := make([]eaclSDK.Header, 0, ln) for i := range xHdrs { for j := range xHdrs[i] { - res = append(res, xHdrs[i][j]) + res = append(res, sessionSDK.NewXHeaderFromV2(&xHdrs[i][j])) } } return res } -func (s responseXHeaderSource) GetXHeaders() []session.XHeader { +func (s responseXHeaderSource) GetXHeaders() []eaclSDK.Header { ln := 0 xHdrs := make([][]session.XHeader, 0) @@ -53,11 +55,11 @@ func (s responseXHeaderSource) GetXHeaders() []session.XHeader { xHdrs = append(xHdrs, x) } - res := make([]session.XHeader, 0, ln) + res := make([]eaclSDK.Header, 0, ln) for i := range xHdrs { for j := range xHdrs[i] { - res = append(res, xHdrs[i][j]) + res = append(res, sessionSDK.NewXHeaderFromV2(&xHdrs[i][j])) } }