From 64238fef8c7b739a2ae5648386cf594eb3a162e5 Mon Sep 17 00:00:00 2001 From: Elena Morozova Date: Thu, 13 Oct 2016 09:34:19 -0700 Subject: [PATCH] all: replace loop with single append Signed-off-by: Elena Morozova --- api/server/router/network/network_routes.go | 4 +--- api/server/server.go | 4 +--- daemon/container_operations_unix.go | 4 +--- daemon/graphdriver/devmapper/deviceset.go | 4 +--- daemon/logger/context.go | 4 +--- integration-cli/docker_cli_images_test.go | 4 +--- integration-cli/docker_cli_network_unix_test.go | 8 ++------ integration-cli/docker_cli_ps_test.go | 12 +++--------- integration-cli/docker_cli_volume_test.go | 8 ++------ pkg/discovery/file/file.go | 4 +--- runconfig/opts/throttledevice.go | 4 +--- 11 files changed, 15 insertions(+), 45 deletions(-) diff --git a/api/server/router/network/network_routes.go b/api/server/router/network/network_routes.go index b84cc1d2af..d464545086 100644 --- a/api/server/router/network/network_routes.go +++ b/api/server/router/network/network_routes.go @@ -27,9 +27,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit list := []types.NetworkResource{} if nr, err := n.clusterProvider.GetNetworks(); err == nil { - for _, nw := range nr { - list = append(list, nw) - } + list = append(list, nr...) } // Combine the network list returned by Docker daemon if it is not already diff --git a/api/server/server.go b/api/server/server.go index c184c77674..ccf6748d98 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -146,9 +146,7 @@ func (s *Server) makeHTTPHandler(handler httputils.APIFunc) http.HandlerFunc { // InitRouter initializes the list of routers for the server. // This method also enables the Go profiler if enableProfiler is true. func (s *Server) InitRouter(enableProfiler bool, routers ...router.Router) { - for _, r := range routers { - s.routers = append(s.routers, r) - } + s.routers = append(s.routers, routers...) m := s.createMux() if enableProfiler { diff --git a/daemon/container_operations_unix.go b/daemon/container_operations_unix.go index 930da7e7b3..f94d15cbeb 100644 --- a/daemon/container_operations_unix.go +++ b/daemon/container_operations_unix.go @@ -56,9 +56,7 @@ func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]s child.Config.ExposedPorts, ) - for _, envVar := range link.ToEnv() { - env = append(env, envVar) - } + env = append(env, link.ToEnv()...) } return env, nil diff --git a/daemon/graphdriver/devmapper/deviceset.go b/daemon/graphdriver/devmapper/deviceset.go index b1ee8497ff..a7ac29ed58 100644 --- a/daemon/graphdriver/devmapper/deviceset.go +++ b/daemon/graphdriver/devmapper/deviceset.go @@ -583,9 +583,7 @@ func (devices *DeviceSet) createFilesystem(info *devInfo) (err error) { devname := info.DevName() args := []string{} - for _, arg := range devices.mkfsArgs { - args = append(args, arg) - } + args = append(args, devices.mkfsArgs...) args = append(args, devname) diff --git a/daemon/logger/context.go b/daemon/logger/context.go index 2b0e071f66..085ab01a18 100644 --- a/daemon/logger/context.go +++ b/daemon/logger/context.go @@ -75,9 +75,7 @@ func (ctx *Context) Hostname() (string, error) { // arguments. func (ctx *Context) Command() string { terms := []string{ctx.ContainerEntrypoint} - for _, arg := range ctx.ContainerArgs { - terms = append(terms, arg) - } + terms = append(terms, ctx.ContainerArgs...) command := strings.Join(terms, " ") return command } diff --git a/integration-cli/docker_cli_images_test.go b/integration-cli/docker_cli_images_test.go index 5b031f9677..3b678a2586 100644 --- a/integration-cli/docker_cli_images_test.go +++ b/integration-cli/docker_cli_images_test.go @@ -333,9 +333,7 @@ func (s *DockerSuite) TestImagesFormat(c *check.C) { expected := []string{"myimage", "myimage"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) } diff --git a/integration-cli/docker_cli_network_unix_test.go b/integration-cli/docker_cli_network_unix_test.go index 4104adf404..00864d8a02 100644 --- a/integration-cli/docker_cli_network_unix_test.go +++ b/integration-cli/docker_cli_network_unix_test.go @@ -288,9 +288,7 @@ func (s *DockerSuite) TestNetworkLsFormat(c *check.C) { expected := []string{"bridge", "host", "none"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) } @@ -312,9 +310,7 @@ func (s *DockerSuite) TestNetworkLsFormatDefaultFormat(c *check.C) { expected := []string{"bridge default", "host default", "none default"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) } diff --git a/integration-cli/docker_cli_ps_test.go b/integration-cli/docker_cli_ps_test.go index 9cbe622a5a..33e9f51732 100644 --- a/integration-cli/docker_cli_ps_test.go +++ b/integration-cli/docker_cli_ps_test.go @@ -566,9 +566,7 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) { lines := strings.Split(strings.TrimSpace(string(out)), "\n") expected := []string{"parent", "child,parent/linkedone"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with non-truncated names: %v, got: %v", expected, names)) //now list without turning off truncation and make sure we only get the non-link names @@ -576,9 +574,7 @@ func (s *DockerSuite) TestPsFormatMultiNames(c *check.C) { lines = strings.Split(strings.TrimSpace(string(out)), "\n") expected = []string{"parent", "child"} var truncNames []string - for _, l := range lines { - truncNames = append(truncNames, l) - } + truncNames = append(truncNames, lines...) c.Assert(expected, checker.DeepEquals, truncNames, check.Commentf("Expected array with truncated names: %v, got: %v", expected, truncNames)) } @@ -592,9 +588,7 @@ func (s *DockerSuite) TestPsNamesMultipleTime(c *check.C) { lines := strings.Split(strings.TrimSpace(string(out)), "\n") expected := []string{"test2 test2", "test1 test1"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names)) } diff --git a/integration-cli/docker_cli_volume_test.go b/integration-cli/docker_cli_volume_test.go index d6fd1bff20..a9c8b61de4 100644 --- a/integration-cli/docker_cli_volume_test.go +++ b/integration-cli/docker_cli_volume_test.go @@ -106,9 +106,7 @@ func (s *DockerSuite) TestVolumeLsFormat(c *check.C) { expected := []string{"aaa", "soo", "test"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) } @@ -132,9 +130,7 @@ func (s *DockerSuite) TestVolumeLsFormatDefaultFormat(c *check.C) { expected := []string{"aaa default", "soo default", "test default"} var names []string - for _, l := range lines { - names = append(names, l) - } + names = append(names, lines...) c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names)) } diff --git a/pkg/discovery/file/file.go b/pkg/discovery/file/file.go index b4f870b864..2b8e27b754 100644 --- a/pkg/discovery/file/file.go +++ b/pkg/discovery/file/file.go @@ -45,9 +45,7 @@ func parseFileContent(content []byte) []string { // Trim additional spaces caused by above stripping. line = strings.TrimSpace(line) } - for _, ip := range discovery.Generate(line) { - result = append(result, ip) - } + result = append(result, discovery.Generate(line)...) } return result } diff --git a/runconfig/opts/throttledevice.go b/runconfig/opts/throttledevice.go index 3a104b86f8..5024324298 100644 --- a/runconfig/opts/throttledevice.go +++ b/runconfig/opts/throttledevice.go @@ -100,9 +100,7 @@ func (opt *ThrottledeviceOpt) String() string { // GetList returns a slice of pointers to ThrottleDevices. func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice { var throttledevice []*blkiodev.ThrottleDevice - for _, v := range opt.values { - throttledevice = append(throttledevice, v) - } + throttledevice = append(throttledevice, opt.values...) return throttledevice }