From 4e34a5438a4095081273b84248ba466297916b3a Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Thu, 25 Apr 2024 14:15:25 +0200 Subject: [PATCH] reduce memory preallocation for GetResourceExceptions Signed-off-by: Matthias Bertschy --- exceptions/exceptionprocessor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exceptions/exceptionprocessor.go b/exceptions/exceptionprocessor.go index 81ef1a8a..e399014a 100644 --- a/exceptions/exceptionprocessor.go +++ b/exceptions/exceptionprocessor.go @@ -140,7 +140,8 @@ func alertObjectToWorkloads(obj *reporthandling.AlertObject) []workloadinterface // GetResourceException get exceptions of single resource func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExceptionPolicy, workload workloadinterface.IMetadata, clusterName string) []armotypes.PostureExceptionPolicy { - postureExceptionPolicy := make([]armotypes.PostureExceptionPolicy, 0, len(ruleExceptions)) + // no pre-allocation since most of the time it's empty or has only one element + var postureExceptionPolicy []armotypes.PostureExceptionPolicy for _, ruleException := range ruleExceptions { for _, resourceToPin := range ruleException.Resources { @@ -151,7 +152,7 @@ func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExce } } - return postureExceptionPolicy[:len(postureExceptionPolicy):len(postureExceptionPolicy)] // shrink capacity + return postureExceptionPolicy } // compareMetadata - compare namespace and kind