oci/caps: minor optimization in init
@@ -12,18 +12,25 @@ 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{
+ 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 (
// CapabilityMapping maps linux capability name to its value of capability.Cap type
