Skip to content

Commit cdee1b3

Browse files
committed
libct/cap: preallocate slices
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent b7da167 commit cdee1b3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libcontainer/capabilities/capabilities.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func New(capConfig *configs.Capabilities) (*Caps, error) {
7575
// equivalent, and returns them as a slice. Unknown or unavailable capabilities
7676
// are not returned, but appended to unknownCaps.
7777
func capSlice(caps []string, unknownCaps map[string]struct{}) []capability.Cap {
78-
var out []capability.Cap
78+
out := make([]capability.Cap, 0, len(caps))
7979
for _, c := range caps {
8080
if v, ok := capabilityMap[c]; !ok {
8181
unknownCaps[c] = struct{}{}
@@ -88,7 +88,7 @@ func capSlice(caps []string, unknownCaps map[string]struct{}) []capability.Cap {
8888

8989
// mapKeys returns the keys of input in sorted order
9090
func mapKeys(input map[string]struct{}) []string {
91-
var keys []string
91+
keys := make([]string, 0, len(input))
9292
for c := range input {
9393
keys = append(keys, c)
9494
}

0 commit comments

Comments
 (0)