From e963179c790ec49b28fae0d7ebc0d9d2b3ac0b72 Mon Sep 17 00:00:00 2001 From: unclejack Date: Wed, 14 May 2014 14:17:58 +0300 Subject: [PATCH] don't call sort for every add in history This moves the call to sort in daemon/history to a function to be called explicitly when we're done adding elements to the list. This speeds up `docker ps`. Docker-DCO-1.1-Signed-off-by: Cristian Staretu (github: unclejack) --- daemon/daemon.go | 1 + daemon/history.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/daemon/daemon.go b/daemon/daemon.go index 38a107bba3..33ddb87ae4 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -85,6 +85,7 @@ func (daemon *Daemon) List() []*Container { for e := daemon.containers.Front(); e != nil; e = e.Next() { containers.Add(e.Value.(*Container)) } + containers.Sort() return *containers } diff --git a/daemon/history.go b/daemon/history.go index 57a00a2090..0b125ad2b3 100644 --- a/daemon/history.go +++ b/daemon/history.go @@ -26,5 +26,8 @@ func (history *History) Swap(i, j int) { func (history *History) Add(container *Container) { *history = append(*history, container) +} + +func (history *History) Sort() { sort.Sort(history) }