From 1bdbd6ed22823109675ad4d0b6dbbf55d0dd00a9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 19 Jan 2022 14:32:10 +0300 Subject: [PATCH] [#1094] eacl/v2: preallocate slice in `headersFromObject` Signed-off-by: Evgenii Stratonikov --- pkg/services/object/acl/eacl/v2/object.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/services/object/acl/eacl/v2/object.go b/pkg/services/object/acl/eacl/v2/object.go index a31059de8..ec610aeb6 100644 --- a/pkg/services/object/acl/eacl/v2/object.go +++ b/pkg/services/object/acl/eacl/v2/object.go @@ -40,9 +40,12 @@ func u64Value(v uint64) string { } func headersFromObject(obj *object.Object, addr *objectSDK.Address) []eaclSDK.Header { - // TODO: optimize allocs - res := make([]eaclSDK.Header, 0) + var count int + for obj := obj; obj != nil; obj = obj.GetParent() { + count += 9 + len(obj.Attributes()) + } + res := make([]eaclSDK.Header, 0, count) for ; obj != nil; obj = obj.GetParent() { res = append(res, cidHeader(addr.ContainerID()), @@ -85,13 +88,9 @@ func headersFromObject(obj *object.Object, addr *objectSDK.Address) []eaclSDK.He ) attrs := obj.Attributes() - hs := make([]eaclSDK.Header, 0, len(attrs)) - for i := range attrs { - hs = append(hs, attrs[i]) + res = append(res, attrs[i]) } - - res = append(res, hs...) } return res