Pārlūkot izejas kodu

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 11 gadi atpakaļ
vecāks
revīzija
e963179c79
2 mainītis faili ar 4 papildinājumiem un 0 dzēšanām
  1. 1 0
      daemon/daemon.go
  2. 3 0
      daemon/history.go

+ 1 - 0
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
 }
 

+ 3 - 0
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)
 }