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

Merge pull request #27360 from morelena/loop_append

all: replace loop with single append
This commit is contained in:
Alexander Morozov 2016-10-13 14:52:59 -07:00 committed by GitHub
commit f299335e6e
11 changed files with 15 additions and 45 deletions

View file

@ -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, nr...)
list = append(list, nw)
}
} }
// 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

View file

@ -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, routers...)
s.routers = append(s.routers, r)
}
m := s.createMux() m := s.createMux()
if enableProfiler { if enableProfiler {

View file

@ -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, link.ToEnv()...)
env = append(env, envVar)
}
} }
return env, nil return env, nil

View file

@ -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, devices.mkfsArgs...)
args = append(args, arg)
}
args = append(args, devname) args = append(args, devname)

View file

@ -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, ctx.ContainerArgs...)
terms = append(terms, arg)
}
command := strings.Join(terms, " ") command := strings.Join(terms, " ")
return command return command
} }

View file

@ -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, lines...)
names = append(names, l)
}
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))
} }

View file

@ -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, lines...)
names = append(names, l)
}
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, lines...)
names = append(names, l)
}
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))
} }

View file

@ -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, lines...)
names = append(names, l)
}
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, lines...)
truncNames = append(truncNames, l)
}
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, lines...)
names = append(names, l)
}
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))
} }

View file

@ -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, lines...)
names = append(names, l)
}
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, lines...)
names = append(names, l)
}
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))
} }

View file

@ -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, discovery.Generate(line)...)
result = append(result, ip)
}
} }
return result return result
} }

View file

@ -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, opt.values...)
throttledevice = append(throttledevice, v)
}
return throttledevice return throttledevice
} }