Skip to content

Commit

Permalink
util: Optimize slice lengths in UnionSyscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrozek authored and k8s-ci-robot committed Oct 6, 2022
1 parent 4723bc0 commit 1bc5a47
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/pkg/util/union_syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import (
)

func UnionSyscalls(baseSyscalls, appliedSyscalls []*seccompprofile.Syscall) []*seccompprofile.Syscall {
allSyscalls := make(map[seccomp.Action]map[string]bool)
longestLen := len(baseSyscalls)
if len(appliedSyscalls) > longestLen {
longestLen = len(appliedSyscalls)
}

allSyscalls := make(map[seccomp.Action]map[string]bool, longestLen)
for _, b := range baseSyscalls {
allSyscalls[b.Action] = make(map[string]bool)
for _, n := range b.Names {
Expand All @@ -38,7 +43,7 @@ func UnionSyscalls(baseSyscalls, appliedSyscalls []*seccompprofile.Syscall) []*s
allSyscalls[s.Action][n] = true
}
}
finalSyscalls := make([]*seccompprofile.Syscall, 0, len(appliedSyscalls)+len(baseSyscalls))
finalSyscalls := make([]*seccompprofile.Syscall, 0, longestLen)
for action, names := range allSyscalls {
syscall := seccompprofile.Syscall{
Action: action,
Expand Down

0 comments on commit 1bc5a47

Please sign in to comment.