1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

use make slice to store objects to improve efficiency

Signed-off-by: allencloud <allen.sun@daocloud.io>
This commit is contained in:
allencloud 2017-04-14 11:02:28 +08:00
parent 41f4c3cf7e
commit ac245e2845
5 changed files with 5 additions and 5 deletions

View file

@ -37,7 +37,7 @@ func (c *Cluster) getNetworks(filters *swarmapi.ListNetworksRequest_Filters) ([]
return nil, err return nil, err
} }
var networks []apitypes.NetworkResource networks := make([]apitypes.NetworkResource, 0, len(r.Networks))
for _, network := range r.Networks { for _, network := range r.Networks {
networks = append(networks, convert.BasicNetworkFromGRPC(*network)) networks = append(networks, convert.BasicNetworkFromGRPC(*network))

View file

@ -34,7 +34,7 @@ func (c *Cluster) GetNodes(options apitypes.NodeListOptions) ([]types.Node, erro
return nil, err return nil, err
} }
nodes := []types.Node{} nodes := make([]types.Node, 0, len(r.Nodes))
for _, node := range r.Nodes { for _, node := range r.Nodes {
nodes = append(nodes, convert.NodeFromGRPC(*node)) nodes = append(nodes, convert.NodeFromGRPC(*node))

View file

@ -48,7 +48,7 @@ func (c *Cluster) GetSecrets(options apitypes.SecretListOptions) ([]types.Secret
return nil, err return nil, err
} }
secrets := []types.Secret{} secrets := make([]types.Secret, 0, len(r.Secrets))
for _, secret := range r.Secrets { for _, secret := range r.Secrets {
secrets = append(secrets, convert.SecretFromGRPC(secret)) secrets = append(secrets, convert.SecretFromGRPC(secret))

View file

@ -67,7 +67,7 @@ func (c *Cluster) GetServices(options apitypes.ServiceListOptions) ([]types.Serv
return nil, err return nil, err
} }
services := []types.Service{} services := make([]types.Service, 0, len(r.Services))
for _, service := range r.Services { for _, service := range r.Services {
if options.Filters.Include("mode") { if options.Filters.Include("mode") {

View file

@ -60,7 +60,7 @@ func (c *Cluster) GetTasks(options apitypes.TaskListOptions) ([]types.Task, erro
return nil, err return nil, err
} }
tasks := []types.Task{} tasks := make([]types.Task, 0, len(r.Tasks))
for _, task := range r.Tasks { for _, task := range r.Tasks {
if task.Spec.GetContainer() != nil { if task.Spec.GetContainer() != nil {