From 1bc5a47044c523fe7936c3916fce7bcf3fcfb3f9 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 29 Sep 2022 13:00:34 +0200 Subject: [PATCH] util: Optimize slice lengths in UnionSyscalls --- internal/pkg/util/union_syscalls.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/pkg/util/union_syscalls.go b/internal/pkg/util/union_syscalls.go index 0b76a7b411..5eaf80bdcd 100644 --- a/internal/pkg/util/union_syscalls.go +++ b/internal/pkg/util/union_syscalls.go @@ -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 { @@ -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,