From 253752538d260369d2ae3f7ddb93a825ffc230d8 Mon Sep 17 00:00:00 2001 From: Paul Cacheux Date: Thu, 11 Jan 2024 17:14:14 +0100 Subject: [PATCH] fix pre-allocation computation in dentry resolver (#21946) [CWS] fix pre-allocation computation in dentry resolver --- pkg/security/resolvers/dentry/resolver.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/security/resolvers/dentry/resolver.go b/pkg/security/resolvers/dentry/resolver.go index 2bf30caa807156..f0b4b09f2b68b2 100644 --- a/pkg/security/resolvers/dentry/resolver.go +++ b/pkg/security/resolvers/dentry/resolver.go @@ -329,13 +329,15 @@ func computeFilenameFromParts(parts []string) string { return "/" } - var builder strings.Builder - // pre-allocation + prealloc := 0 for _, part := range parts { - builder.Grow(len(part) + 1) + prealloc += len(part) + 1 } + var builder strings.Builder + builder.Grow(prealloc) + // reverse iteration for i := 0; i < len(parts); i++ { j := len(parts) - 1 - i