Skip to content

Commit

Permalink
fix pre-allocation computation in dentry resolver (#21946)
Browse files Browse the repository at this point in the history
[CWS] fix pre-allocation computation in dentry resolver
  • Loading branch information
paulcacheux authored Jan 11, 2024
1 parent 515d0ad commit 2537525
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/security/resolvers/dentry/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2537525

Please sign in to comment.