Browse code

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 <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/05/14 20:17:58
Showing 2 changed files
... ...
@@ -85,6 +85,7 @@ func (daemon *Daemon) List() []*Container {
85 85
 	for e := daemon.containers.Front(); e != nil; e = e.Next() {
86 86
 		containers.Add(e.Value.(*Container))
87 87
 	}
88
+	containers.Sort()
88 89
 	return *containers
89 90
 }
90 91
 
... ...
@@ -26,5 +26,8 @@ func (history *History) Swap(i, j int) {
26 26
 
27 27
 func (history *History) Add(container *Container) {
28 28
 	*history = append(*history, container)
29
+}
30
+
31
+func (history *History) Sort() {
29 32
 	sort.Sort(history)
30 33
 }