From e66abdf7bbf104c8ba0447b5a33d4fe62620fae3 Mon Sep 17 00:00:00 2001 From: Anton Tiurin Date: Wed, 8 Apr 2015 00:41:28 +0300 Subject: [PATCH] [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 --- cluster/engine.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cluster/engine.go b/cluster/engine.go index 7428043462..ef5e76de61 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -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) }