mirror of
https://github.com/docker/docs.git
synced 2026-10-31 10:34:26 +03:00
[SwarmCluster] Remove an extra RLock in Engine.Container
Engine.Container uses an array of containers from Engine.Containers, which is built under an internal RLock, so the external RLock is useless. Also allocate enough memory for the array of containers (images). Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
This commit is contained in:
@@ -422,8 +422,8 @@ func (e *Engine) Events(h EventHandler) error {
|
||||
|
||||
// Containers returns all the containers in the engine.
|
||||
func (e *Engine) Containers() []*Container {
|
||||
containers := []*Container{}
|
||||
e.RLock()
|
||||
containers := make([]*Container, 0, len(e.containers))
|
||||
for _, container := range e.containers {
|
||||
containers = append(containers, container)
|
||||
}
|
||||
@@ -438,9 +438,6 @@ func (e *Engine) Container(IDOrName string) *Container {
|
||||
return nil
|
||||
}
|
||||
|
||||
e.RLock()
|
||||
defer e.RUnlock()
|
||||
|
||||
for _, container := range e.Containers() {
|
||||
// Match ID prefix.
|
||||
if strings.HasPrefix(container.Id, IDOrName) {
|
||||
@@ -460,9 +457,9 @@ func (e *Engine) Container(IDOrName string) *Container {
|
||||
|
||||
// Images returns all the images in the engine
|
||||
func (e *Engine) Images() []*Image {
|
||||
images := []*Image{}
|
||||
e.RLock()
|
||||
|
||||
images := make([]*Image, 0, len(e.images))
|
||||
for _, image := range e.images {
|
||||
images = append(images, image)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user