Browse Source

Merge pull request #27360 from morelena/loop_append

all: replace loop with single append
Alexander Morozov 8 years ago
parent
commit
f299335e6e

+ 1 - 3
api/server/router/network/network_routes.go

@@ -27,9 +27,7 @@ func (n *networkRouter) getNetworksList(ctx context.Context, w http.ResponseWrit
 	list := []types.NetworkResource{}
 	list := []types.NetworkResource{}
 
 
 	if nr, err := n.clusterProvider.GetNetworks(); err == nil {
 	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
 	// Combine the network list returned by Docker daemon if it is not already

+ 1 - 3
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.
 // InitRouter initializes the list of routers for the server.
 // This method also enables the Go profiler if enableProfiler is true.
 // This method also enables the Go profiler if enableProfiler is true.
 func (s *Server) InitRouter(enableProfiler bool, routers ...router.Router) {
 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()
 	m := s.createMux()
 	if enableProfiler {
 	if enableProfiler {

+ 1 - 3
daemon/container_operations_unix.go

@@ -56,9 +56,7 @@ func (daemon *Daemon) setupLinkedContainers(container *container.Container) ([]s
 			child.Config.ExposedPorts,
 			child.Config.ExposedPorts,
 		)
 		)
 
 
-		for _, envVar := range link.ToEnv() {
-			env = append(env, envVar)
-		}
+		env = append(env, link.ToEnv()...)
 	}
 	}
 
 
 	return env, nil
 	return env, nil

+ 1 - 3
daemon/graphdriver/devmapper/deviceset.go

@@ -583,9 +583,7 @@ func (devices *DeviceSet) createFilesystem(info *devInfo) (err error) {
 	devname := info.DevName()
 	devname := info.DevName()
 
 
 	args := []string{}
 	args := []string{}
-	for _, arg := range devices.mkfsArgs {
-		args = append(args, arg)
-	}
+	args = append(args, devices.mkfsArgs...)
 
 
 	args = append(args, devname)
 	args = append(args, devname)
 
 

+ 1 - 3
daemon/logger/context.go

@@ -75,9 +75,7 @@ func (ctx *Context) Hostname() (string, error) {
 // arguments.
 // arguments.
 func (ctx *Context) Command() string {
 func (ctx *Context) Command() string {
 	terms := []string{ctx.ContainerEntrypoint}
 	terms := []string{ctx.ContainerEntrypoint}
-	for _, arg := range ctx.ContainerArgs {
-		terms = append(terms, arg)
-	}
+	terms = append(terms, ctx.ContainerArgs...)
 	command := strings.Join(terms, " ")
 	command := strings.Join(terms, " ")
 	return command
 	return command
 }
 }

+ 1 - 3
integration-cli/docker_cli_images_test.go

@@ -333,9 +333,7 @@ func (s *DockerSuite) TestImagesFormat(c *check.C) {
 
 
 	expected := []string{"myimage", "myimage"}
 	expected := []string{"myimage", "myimage"}
 	var names []string
 	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))
 	c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
 }
 }
 
 

+ 2 - 6
integration-cli/docker_cli_network_unix_test.go

@@ -288,9 +288,7 @@ func (s *DockerSuite) TestNetworkLsFormat(c *check.C) {
 
 
 	expected := []string{"bridge", "host", "none"}
 	expected := []string{"bridge", "host", "none"}
 	var names []string
 	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))
 	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"}
 	expected := []string{"bridge default", "host default", "none default"}
 	var names []string
 	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))
 	c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
 }
 }
 
 

+ 3 - 9
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")
 	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
 	expected := []string{"parent", "child,parent/linkedone"}
 	expected := []string{"parent", "child,parent/linkedone"}
 	var names []string
 	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))
 	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
 	//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")
 	lines = strings.Split(strings.TrimSpace(string(out)), "\n")
 	expected = []string{"parent", "child"}
 	expected = []string{"parent", "child"}
 	var truncNames []string
 	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))
 	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")
 	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
 	expected := []string{"test2 test2", "test1 test1"}
 	expected := []string{"test2 test2", "test1 test1"}
 	var names []string
 	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))
 	c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with names displayed twice: %v, got: %v", expected, names))
 }
 }
 
 

+ 2 - 6
integration-cli/docker_cli_volume_test.go

@@ -106,9 +106,7 @@ func (s *DockerSuite) TestVolumeLsFormat(c *check.C) {
 
 
 	expected := []string{"aaa", "soo", "test"}
 	expected := []string{"aaa", "soo", "test"}
 	var names []string
 	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))
 	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"}
 	expected := []string{"aaa default", "soo default", "test default"}
 	var names []string
 	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))
 	c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
 }
 }
 
 

+ 1 - 3
pkg/discovery/file/file.go

@@ -45,9 +45,7 @@ func parseFileContent(content []byte) []string {
 			// Trim additional spaces caused by above stripping.
 			// Trim additional spaces caused by above stripping.
 			line = strings.TrimSpace(line)
 			line = strings.TrimSpace(line)
 		}
 		}
-		for _, ip := range discovery.Generate(line) {
-			result = append(result, ip)
-		}
+		result = append(result, discovery.Generate(line)...)
 	}
 	}
 	return result
 	return result
 }
 }

+ 1 - 3
runconfig/opts/throttledevice.go

@@ -100,9 +100,7 @@ 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 {
 	var throttledevice []*blkiodev.ThrottleDevice
 	var throttledevice []*blkiodev.ThrottleDevice
-	for _, v := range opt.values {
-		throttledevice = append(throttledevice, v)
-	}
+	throttledevice = append(throttledevice, opt.values...)
 
 
 	return throttledevice
 	return throttledevice
 }
 }