From 0ec6f7ea23ad9162d867bbb70877469d3f95f53b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 16 Sep 2020 14:22:03 +0200 Subject: oci/caps: minor optimization in init Signed-off-by: Sebastiaan van Stijn --- oci/caps/utils.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'oci') diff --git a/oci/caps/utils.go b/oci/caps/utils.go index 3d337b5dd1..9ccb02e04d 100644 --- a/oci/caps/utils.go +++ b/oci/caps/utils.go @@ -12,17 +12,24 @@ var capabilityList Capabilities func init() { last := capability.CAP_LAST_CAP - for _, c := range capability.List() { + rawCaps := capability.List() + capabilityList = make(Capabilities, min(int(last+1), len(rawCaps))) + for i, c := range rawCaps { if c > last { continue } - capabilityList = append(capabilityList, - &CapabilityMapping{ - Key: "CAP_" + strings.ToUpper(c.String()), - Value: c, - }, - ) + capabilityList[i] = &CapabilityMapping{ + Key: "CAP_" + strings.ToUpper(c.String()), + Value: c, + } + } +} + +func min(a, b int) int { + if a < b { + return a } + return b } type ( -- cgit v1.2.1