Skip to content

Commit 4e34a54

Browse files
committed
reduce memory preallocation for GetResourceExceptions
Signed-off-by: Matthias Bertschy <[email protected]>
1 parent d0cb0db commit 4e34a54

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

exceptions/exceptionprocessor.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ func alertObjectToWorkloads(obj *reporthandling.AlertObject) []workloadinterface
140140

141141
// GetResourceException get exceptions of single resource
142142
func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExceptionPolicy, workload workloadinterface.IMetadata, clusterName string) []armotypes.PostureExceptionPolicy {
143-
postureExceptionPolicy := make([]armotypes.PostureExceptionPolicy, 0, len(ruleExceptions))
143+
// no pre-allocation since most of the time it's empty or has only one element
144+
var postureExceptionPolicy []armotypes.PostureExceptionPolicy
144145

145146
for _, ruleException := range ruleExceptions {
146147
for _, resourceToPin := range ruleException.Resources {
@@ -151,7 +152,7 @@ func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExce
151152
}
152153
}
153154

154-
return postureExceptionPolicy[:len(postureExceptionPolicy):len(postureExceptionPolicy)] // shrink capacity
155+
return postureExceptionPolicy
155156
}
156157

157158
// compareMetadata - compare namespace and kind

0 commit comments

Comments
 (0)