linting: Consider pre-allocating sliceVar (prealloc)

While updating, also addressed some redundant fmt.Sprintf()

    opts/throttledevice.go:86:2: Consider pre-allocating `out` (prealloc)
        var out []string
        ^
    opts/ulimit.go:37:2: Consider pre-allocating `out` (prealloc)
        var out []string
        ^
    opts/ulimit.go:47:2: Consider pre-allocating `ulimits` (prealloc)
        var ulimits []*units.Ulimit
        ^
    opts/weightdevice.go:68:2: Consider pre-allocating `out` (prealloc)
        var out []string
        ^
    cli/context/store/metadatastore.go:96:2: Consider pre-allocating `res` (prealloc)
        var res []Metadata
        ^
    cli/context/store/store.go:127:2: Consider pre-allocating `names` (prealloc)
        var names []string
        ^
    cli/compose/loader/loader.go:223:2: Consider pre-allocating `keys` (prealloc)
        var keys []string
        ^
    cli/compose/loader/loader.go:397:2: Consider pre-allocating `services` (prealloc)
        var services []types.ServiceConfig
        ^
    cli/command/stack/loader/loader.go:63:2: Consider pre-allocating `msgs` (prealloc)
        var msgs []string
        ^
    cli/command/stack/loader/loader.go:118:2: Consider pre-allocating `configFiles` (prealloc)
        var configFiles []composetypes.ConfigFile
        ^
    cli/command/formatter/container.go:245:2: Consider pre-allocating `joinLabels` (prealloc)
        var joinLabels []string
        ^
    cli/command/formatter/container.go:265:2: Consider pre-allocating `mounts` (prealloc)
        var mounts []string
        ^
    cli/command/formatter/container.go:316:2: Consider pre-allocating `result` (prealloc)
        var result []string
        ^
    cli/command/formatter/displayutils.go:43:2: Consider pre-allocating `display` (prealloc)
        var (
        ^
    cli/command/formatter/volume.go:103:2: Consider pre-allocating `joinLabels` (prealloc)
        var joinLabels []string
        ^
    cli-plugins/manager/manager_test.go:49:2: Consider pre-allocating `dirs` (prealloc)
        var dirs []string
        ^
    cli/command/swarm/init.go:69:2: Consider pre-allocating `defaultAddrPool` (prealloc)
        var defaultAddrPool []string
        ^
    cli/command/manifest/push.go:195:2: Consider pre-allocating `blobReqs` (prealloc)
        var blobReqs []manifestBlob
        ^
    cli/command/secret/formatter.go:111:2: Consider pre-allocating `joinLabels` (prealloc)
        var joinLabels []string
        ^
    cli/command/network/formatter.go:104:2: Consider pre-allocating `joinLabels` (prealloc)
        var joinLabels []string
        ^
    cli/command/context/list.go:52:2: Consider pre-allocating `contexts` (prealloc)
        var contexts []*formatter.ClientContext
        ^
    cli/command/config/formatter.go:104:2: Consider pre-allocating `joinLabels` (prealloc)
        var joinLabels []string
        ^
    cli/command/trust/common_test.go:23:2: Consider pre-allocating `targetNames` (prealloc)
        var targetNames []string
        ^
    cli/command/service/generic_resource_opts.go:55:2: Consider pre-allocating `generic` (prealloc)
        var generic []swarm.GenericResource
        ^
    cli/command/service/generic_resource_opts.go:98:2: Consider pre-allocating `l` (prealloc)
        var l []swarm.GenericResource
        ^
    cli/command/service/opts.go:378:2: Consider pre-allocating `netAttach` (prealloc)
        var netAttach []swarm.NetworkAttachmentConfig
        ^
    cli/command/service/update.go:731:2: Consider pre-allocating `limits` (prealloc)
        var limits []*units.Ulimit
        ^
    cli/command/service/update.go:1315:2: Consider pre-allocating `newNetworks` (prealloc)
        var newNetworks []swarm.NetworkAttachmentConfig
        ^
    cli/command/service/update.go:1514:2: Consider pre-allocating `out` (prealloc)
        var out []string
        ^
    cli/compose/convert/service.go:713:2: Consider pre-allocating `ulimits` (prealloc)
        var ulimits []*units.Ulimit
        ^
    cli/compose/convert/volume.go:13:2: Consider pre-allocating `mounts` (prealloc)
        var mounts []mount.Mount
        ^
    cli/command/stack/swarm/list.go:39:2: Consider pre-allocating `stacks` (prealloc)
        var stacks []*formatter.Stack
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-09-03 20:07:29 +02:00
parent efbcdce9b9
commit d0dee3cebe
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
26 changed files with 60 additions and 51 deletions

View File

@ -46,7 +46,7 @@ func TestListPluginCandidates(t *testing.T) {
) )
defer dir.Remove() defer dir.Remove()
var dirs []string dirs := make([]string, 0, 6)
for _, d := range []string{"plugins1", "nonexistent", "plugins2", "plugins3", "plugins4", "plugins5"} { for _, d := range []string{"plugins1", "nonexistent", "plugins2", "plugins3", "plugins4", "plugins5"} {
dirs = append(dirs, dir.Join(d)) dirs = append(dirs, dir.Join(d))
} }

View File

@ -101,7 +101,7 @@ func (c *configContext) Labels() string {
if mapLabels == nil { if mapLabels == nil {
return "" return ""
} }
var joinLabels []string joinLabels := make([]string, 0, len(mapLabels))
for k, v := range mapLabels { for k, v := range mapLabels {
joinLabels = append(joinLabels, k+"="+v) joinLabels = append(joinLabels, k+"="+v)
} }

View File

@ -51,7 +51,7 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
var ( var (
curContext = dockerCli.CurrentContext() curContext = dockerCli.CurrentContext()
curFound bool curFound bool
contexts []*formatter.ClientContext contexts = make([]*formatter.ClientContext, 0, len(contextMap))
) )
for _, rawMeta := range contextMap { for _, rawMeta := range contextMap {
isCurrent := rawMeta.Name == curContext isCurrent := rawMeta.Name == curContext

View File

@ -245,7 +245,7 @@ func (c *ContainerContext) Labels() string {
return "" return ""
} }
var joinLabels []string joinLabels := make([]string, 0, len(c.c.Labels))
for k, v := range c.c.Labels { for k, v := range c.c.Labels {
joinLabels = append(joinLabels, k+"="+v) joinLabels = append(joinLabels, k+"="+v)
} }
@ -265,7 +265,7 @@ func (c *ContainerContext) Label(name string) string {
// If the trunc option is set, names can be truncated (ellipsized). // If the trunc option is set, names can be truncated (ellipsized).
func (c *ContainerContext) Mounts() string { func (c *ContainerContext) Mounts() string {
var name string var name string
var mounts []string mounts := make([]string, 0, len(c.c.Mounts))
for _, m := range c.c.Mounts { for _, m := range c.c.Mounts {
if m.Name == "" { if m.Name == "" {
name = m.Source name = m.Source
@ -289,7 +289,7 @@ func (c *ContainerContext) LocalVolumes() string {
} }
} }
return fmt.Sprintf("%d", count) return strconv.Itoa(count)
} }
// Networks returns a comma-separated string of networks that the container is // Networks returns a comma-separated string of networks that the container is
@ -299,7 +299,7 @@ func (c *ContainerContext) Networks() string {
return "" return ""
} }
networks := []string{} networks := make([]string, 0, len(c.c.NetworkSettings.Networks))
for k := range c.c.NetworkSettings.Networks { for k := range c.c.NetworkSettings.Networks {
networks = append(networks, k) networks = append(networks, k)
} }
@ -316,7 +316,7 @@ func DisplayablePorts(ports []types.Port) string {
last uint16 last uint16
} }
groupMap := make(map[string]*portGroup) groupMap := make(map[string]*portGroup)
var result []string var result []string //nolint:prealloc
var hostMappings []string var hostMappings []string
var groupMapKeys []string var groupMapKeys []string
sort.Slice(ports, func(i, j int) bool { sort.Slice(ports, func(i, j int) bool {
@ -331,7 +331,7 @@ func DisplayablePorts(ports []types.Port) string {
hostMappings = append(hostMappings, fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type)) hostMappings = append(hostMappings, fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type))
continue continue
} }
portKey = fmt.Sprintf("%s/%s", port.IP, port.Type) portKey = port.IP + "/" + port.Type
} }
group := groupMap[portKey] group := groupMap[portKey]
@ -372,7 +372,7 @@ func formGroup(key string, start, last uint16) string {
if ip != "" { if ip != "" {
group = fmt.Sprintf("%s:%s->%s", ip, group, group) group = fmt.Sprintf("%s:%s->%s", ip, group, group)
} }
return fmt.Sprintf("%s/%s", group, groupType) return group + "/" + groupType
} }
func comparePorts(i, j types.Port) bool { func comparePorts(i, j types.Port) bool {

View File

@ -41,7 +41,7 @@ func Ellipsis(s string, maxDisplayWidth int) string {
} }
var ( var (
display []int display = make([]int, 0, len(rs))
displayWidth int displayWidth int
) )
for _, r := range rs { for _, r := range rs {

View File

@ -100,7 +100,7 @@ func (c *volumeContext) Labels() string {
return "" return ""
} }
var joinLabels []string joinLabels := make([]string, 0, len(c.v.Labels))
for k, v := range c.v.Labels { for k, v := range c.v.Labels {
joinLabels = append(joinLabels, k+"="+v) joinLabels = append(joinLabels, k+"="+v)
} }

View File

@ -192,9 +192,9 @@ func buildManifestDescriptor(targetRepo *registry.RepositoryInfo, imageManifest
} }
func buildBlobRequestList(imageManifest types.ImageManifest, repoName reference.Named) ([]manifestBlob, error) { func buildBlobRequestList(imageManifest types.ImageManifest, repoName reference.Named) ([]manifestBlob, error) {
var blobReqs []manifestBlob blobs := imageManifest.Blobs()
blobReqs := make([]manifestBlob, 0, len(blobs))
for _, blobDigest := range imageManifest.Blobs() { for _, blobDigest := range blobs {
canonical, err := reference.WithDigest(repoName, blobDigest) canonical, err := reference.WithDigest(repoName, blobDigest)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -101,7 +101,7 @@ func (c *networkContext) Labels() string {
return "" return ""
} }
var joinLabels []string joinLabels := make([]string, 0, len(c.n.Labels))
for k, v := range c.n.Labels { for k, v := range c.n.Labels {
joinLabels = append(joinLabels, k+"="+v) joinLabels = append(joinLabels, k+"="+v)
} }

View File

@ -108,7 +108,7 @@ func (c *secretContext) Labels() string {
if mapLabels == nil { if mapLabels == nil {
return "" return ""
} }
var joinLabels []string joinLabels := make([]string, 0, len(mapLabels))
for k, v := range mapLabels { for k, v := range mapLabels {
joinLabels = append(joinLabels, k+"="+v) joinLabels = append(joinLabels, k+"="+v)
} }

View File

@ -52,7 +52,7 @@ func ParseGenericResources(value []string) ([]swarm.GenericResource, error) {
// genericResourcesFromGRPC converts a GRPC GenericResource to a GenericResource // genericResourcesFromGRPC converts a GRPC GenericResource to a GenericResource
func genericResourcesFromGRPC(genericRes []*swarmapi.GenericResource) []swarm.GenericResource { func genericResourcesFromGRPC(genericRes []*swarmapi.GenericResource) []swarm.GenericResource {
var generic []swarm.GenericResource generic := make([]swarm.GenericResource, 0, len(genericRes))
for _, res := range genericRes { for _, res := range genericRes {
var current swarm.GenericResource var current swarm.GenericResource
@ -95,7 +95,7 @@ func buildGenericResourceMap(genericRes []swarm.GenericResource) (map[string]swa
} }
func buildGenericResourceList(genericRes map[string]swarm.GenericResource) []swarm.GenericResource { func buildGenericResourceList(genericRes map[string]swarm.GenericResource) []swarm.GenericResource {
var l []swarm.GenericResource l := make([]swarm.GenericResource, 0, len(genericRes))
for _, res := range genericRes { for _, res := range genericRes {
l = append(l, res) l = append(l, res)

View File

@ -378,8 +378,9 @@ func resolveNetworkID(ctx context.Context, apiClient client.NetworkAPIClient, ne
} }
func convertNetworks(networks opts.NetworkOpt) []swarm.NetworkAttachmentConfig { func convertNetworks(networks opts.NetworkOpt) []swarm.NetworkAttachmentConfig {
var netAttach []swarm.NetworkAttachmentConfig nws := networks.Value()
for _, net := range networks.Value() { netAttach := make([]swarm.NetworkAttachmentConfig, 0, len(nws))
for _, net := range nws {
netAttach = append(netAttach, swarm.NetworkAttachmentConfig{ netAttach = append(netAttach, swarm.NetworkAttachmentConfig{
Target: net.Target, Target: net.Target,
Aliases: net.Aliases, Aliases: net.Aliases,

View File

@ -727,8 +727,10 @@ func updateUlimits(flags *pflag.FlagSet, ulimits []*units.Ulimit) []*units.Ulimi
newUlimits[ulimit.Name] = ulimit newUlimits[ulimit.Name] = ulimit
} }
} }
if len(newUlimits) == 0 {
var limits []*units.Ulimit return nil
}
limits := make([]*units.Ulimit, 0, len(newUlimits))
for _, ulimit := range newUlimits { for _, ulimit := range newUlimits {
limits = append(limits, ulimit) limits = append(limits, ulimit)
} }
@ -1307,7 +1309,7 @@ func updateNetworks(ctx context.Context, apiClient client.NetworkAPIClient, flag
} }
existingNetworks := make(map[string]struct{}) existingNetworks := make(map[string]struct{})
var newNetworks []swarm.NetworkAttachmentConfig var newNetworks []swarm.NetworkAttachmentConfig //nolint:prealloc
for _, network := range specNetworks { for _, network := range specNetworks {
if _, exists := idsToRemove[network.Target]; exists { if _, exists := idsToRemove[network.Target]; exists {
continue continue
@ -1503,10 +1505,13 @@ func updateCapabilities(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec
} }
func capsList(caps map[string]bool) []string { func capsList(caps map[string]bool) []string {
if len(caps) == 0 {
return nil
}
if caps[opts.AllCapabilities] { if caps[opts.AllCapabilities] {
return []string{opts.AllCapabilities} return []string{opts.AllCapabilities}
} }
var out []string out := make([]string, 0, len(caps))
for c := range caps { for c := range caps {
out = append(out, c) out = append(out, c)
} }

View File

@ -61,7 +61,7 @@ func getDictsFrom(configFiles []composetypes.ConfigFile) []map[string]interface{
} }
func propertyWarnings(properties map[string]string) string { func propertyWarnings(properties map[string]string) string {
var msgs []string msgs := make([]string, 0, len(properties))
for name, description := range properties { for name, description := range properties {
msgs = append(msgs, fmt.Sprintf("%s: %s", name, description)) msgs = append(msgs, fmt.Sprintf("%s: %s", name, description))
} }
@ -129,7 +129,7 @@ func buildEnvironment(env []string) (map[string]string, error) {
} }
func loadConfigFiles(filenames []string, stdin io.Reader) ([]composetypes.ConfigFile, error) { func loadConfigFiles(filenames []string, stdin io.Reader) ([]composetypes.ConfigFile, error) {
var configFiles []composetypes.ConfigFile configFiles := make([]composetypes.ConfigFile, 0, len(filenames))
for _, filename := range filenames { for _, filename := range filenames {
configFile, err := loadConfigFile(filename, stdin) configFile, err := loadConfigFile(filename, stdin)

View File

@ -36,7 +36,7 @@ func GetStacks(dockerCli command.Cli) ([]*formatter.Stack, error) {
ztack.Services++ ztack.Services++
} }
} }
var stacks []*formatter.Stack stacks := make([]*formatter.Stack, 0, len(m))
for _, stack := range m { for _, stack := range m {
stacks = append(stacks, stack) stacks = append(stacks, stack)
} }

View File

@ -66,11 +66,10 @@ func newInitCommand(dockerCli command.Cli) *cobra.Command {
} }
func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) error { func runInit(dockerCli command.Cli, flags *pflag.FlagSet, opts initOptions) error {
var defaultAddrPool []string
client := dockerCli.Client() client := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
defaultAddrPool := make([]string, 0, len(opts.defaultAddrPools))
for _, p := range opts.defaultAddrPools { for _, p := range opts.defaultAddrPools {
defaultAddrPool = append(defaultAddrPool, p.String()) defaultAddrPool = append(defaultAddrPool, p.String())
} }

View File

@ -16,7 +16,7 @@ import (
) )
func TestEventsFormat(t *testing.T) { func TestEventsFormat(t *testing.T) {
var evts []events.Message var evts []events.Message //nolint:prealloc
for i, action := range []events.Action{events.ActionCreate, events.ActionStart, events.ActionAttach, events.ActionDie} { for i, action := range []events.Action{events.ActionCreate, events.ActionStart, events.ActionAttach, events.ActionDie} {
evts = append(evts, events.Message{ evts = append(evts, events.Message{
Status: string(action), Status: string(action),

View File

@ -20,7 +20,7 @@ func TestMatchReleasedSignaturesSortOrder(t *testing.T) {
rows := matchReleasedSignatures(targets) rows := matchReleasedSignatures(targets)
var targetNames []string targetNames := make([]string, 0, len(rows))
for _, r := range rows { for _, r := range rows {
targetNames = append(targetNames, r.SignedTag) targetNames = append(targetNames, r.SignedTag)
} }

View File

@ -710,7 +710,7 @@ func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*units
} }
} }
} }
var ulimits []*units.Ulimit ulimits := make([]*units.Ulimit, 0, len(newUlimits))
for _, ulimit := range newUlimits { for _, ulimit := range newUlimits {
ulimits = append(ulimits, ulimit) ulimits = append(ulimits, ulimit)
} }

View File

@ -12,14 +12,13 @@ type volumes map[string]composetypes.VolumeConfig
// Volumes from compose-file types to engine api types // Volumes from compose-file types to engine api types
func Volumes(serviceVolumes []composetypes.ServiceVolumeConfig, stackVolumes volumes, namespace Namespace) ([]mount.Mount, error) { func Volumes(serviceVolumes []composetypes.ServiceVolumeConfig, stackVolumes volumes, namespace Namespace) ([]mount.Mount, error) {
var mounts []mount.Mount mounts := make([]mount.Mount, 0, len(serviceVolumes))
for _, volumeConfig := range serviceVolumes { for _, volumeConfig := range serviceVolumes {
mount, err := convertVolumeToMount(volumeConfig, stackVolumes, namespace) mnt, err := convertVolumeToMount(volumeConfig, stackVolumes, namespace)
if err != nil { if err != nil {
return nil, err return nil, err
} }
mounts = append(mounts, mount) mounts = append(mounts, mnt)
} }
return mounts, nil return mounts, nil
} }

View File

@ -220,7 +220,7 @@ func GetUnsupportedProperties(configDicts ...map[string]interface{}) []string {
} }
func sortedKeys(set map[string]bool) []string { func sortedKeys(set map[string]bool) []string {
var keys []string keys := make([]string, 0, len(set))
for key := range set { for key := range set {
keys = append(keys, key) keys = append(keys, key)
} }
@ -394,7 +394,7 @@ func formatInvalidKeyError(keyPrefix string, key interface{}) error {
// LoadServices produces a ServiceConfig map from a compose file Dict // LoadServices produces a ServiceConfig map from a compose file Dict
// the servicesDict is not validated if directly used. Use Load() to enable validation // the servicesDict is not validated if directly used. Use Load() to enable validation
func LoadServices(servicesDict map[string]interface{}, workingDir string, lookupEnv template.Mapping) ([]types.ServiceConfig, error) { func LoadServices(servicesDict map[string]interface{}, workingDir string, lookupEnv template.Mapping) ([]types.ServiceConfig, error) {
var services []types.ServiceConfig services := make([]types.ServiceConfig, 0, len(servicesDict))
for name, serviceDef := range servicesDict { for name, serviceDef := range servicesDict {
serviceConfig, err := LoadService(name, serviceDef.(map[string]interface{}), workingDir, lookupEnv) serviceConfig, err := LoadService(name, serviceDef.(map[string]interface{}), workingDir, lookupEnv)

View File

@ -109,7 +109,7 @@ func (s *metadataStore) list() ([]Metadata, error) {
} }
return nil, err return nil, err
} }
var res []Metadata res := make([]Metadata, 0, len(ctxDirs))
for _, dir := range ctxDirs { for _, dir := range ctxDirs {
c, err := s.getByID(contextdir(dir)) c, err := s.getByID(contextdir(dir))
if err != nil { if err != nil {

View File

@ -125,7 +125,7 @@ func Names(s Lister) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var names []string names := make([]string, 0, len(list))
for _, item := range list { for _, item := range list {
names = append(names, item.Name) names = append(names, item.Name)
} }

View File

@ -55,14 +55,18 @@ func PlatformSpecFromOCI(p *ocispec.Platform) *manifestlist.PlatformSpec {
// Blobs returns the digests for all the blobs referenced by this manifest // Blobs returns the digests for all the blobs referenced by this manifest
func (i ImageManifest) Blobs() []digest.Digest { func (i ImageManifest) Blobs() []digest.Digest {
digests := []digest.Digest{} var digests []digest.Digest
switch { switch {
case i.SchemaV2Manifest != nil: case i.SchemaV2Manifest != nil:
for _, descriptor := range i.SchemaV2Manifest.References() { refs := i.SchemaV2Manifest.References()
digests = make([]digest.Digest, 0, len(refs))
for _, descriptor := range refs {
digests = append(digests, descriptor.Digest) digests = append(digests, descriptor.Digest)
} }
case i.OCIManifest != nil: case i.OCIManifest != nil:
for _, descriptor := range i.OCIManifest.References() { refs := i.OCIManifest.References()
digests = make([]digest.Digest, 0, len(refs))
for _, descriptor := range refs {
digests = append(digests, descriptor.Digest) digests = append(digests, descriptor.Digest)
} }
} }

View File

@ -62,9 +62,8 @@ type ThrottledeviceOpt struct {
// NewThrottledeviceOpt creates a new ThrottledeviceOpt // NewThrottledeviceOpt creates a new ThrottledeviceOpt
func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt { func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt {
values := []*blkiodev.ThrottleDevice{}
return ThrottledeviceOpt{ return ThrottledeviceOpt{
values: values, values: []*blkiodev.ThrottleDevice{},
validator: validator, validator: validator,
} }
} }
@ -85,7 +84,7 @@ func (opt *ThrottledeviceOpt) Set(val string) error {
// String returns ThrottledeviceOpt values as a string. // String returns ThrottledeviceOpt values as a string.
func (opt *ThrottledeviceOpt) String() string { func (opt *ThrottledeviceOpt) String() string {
var out []string out := make([]string, 0, len(opt.values))
for _, v := range opt.values { for _, v := range opt.values {
out = append(out, v.String()) out = append(out, v.String())
} }
@ -95,7 +94,9 @@ func (opt *ThrottledeviceOpt) String() string {
// GetList returns a slice of pointers to ThrottleDevices. // GetList returns a slice of pointers to ThrottleDevices.
func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice { func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice {
return append([]*blkiodev.ThrottleDevice{}, opt.values...) out := make([]*blkiodev.ThrottleDevice, 0, len(opt.values))
copy(out, opt.values)
return out
} }
// Type returns the option type // Type returns the option type

View File

@ -34,7 +34,7 @@ func (o *UlimitOpt) Set(val string) error {
// String returns Ulimit values as a string. Values are sorted by name. // String returns Ulimit values as a string. Values are sorted by name.
func (o *UlimitOpt) String() string { func (o *UlimitOpt) String() string {
var out []string out := make([]string, 0, len(*o.values))
for _, v := range *o.values { for _, v := range *o.values {
out = append(out, v.String()) out = append(out, v.String())
} }
@ -44,7 +44,7 @@ func (o *UlimitOpt) String() string {
// GetList returns a slice of pointers to Ulimits. Values are sorted by name. // GetList returns a slice of pointers to Ulimits. Values are sorted by name.
func (o *UlimitOpt) GetList() []*units.Ulimit { func (o *UlimitOpt) GetList() []*units.Ulimit {
var ulimits []*units.Ulimit ulimits := make([]*units.Ulimit, 0, len(*o.values))
for _, v := range *o.values { for _, v := range *o.values {
ulimits = append(ulimits, v) ulimits = append(ulimits, v)
} }

View File

@ -65,7 +65,7 @@ func (opt *WeightdeviceOpt) Set(val string) error {
// String returns WeightdeviceOpt values as a string. // String returns WeightdeviceOpt values as a string.
func (opt *WeightdeviceOpt) String() string { func (opt *WeightdeviceOpt) String() string {
var out []string out := make([]string, 0, len(opt.values))
for _, v := range opt.values { for _, v := range opt.values {
out = append(out, v.String()) out = append(out, v.String())
} }