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)
This commit is contained in:
unclejack 2014-05-14 14:17:58 +03:00
parent f637eaca5d
commit e963179c79
2 changed files with 4 additions and 0 deletions

View file

@ -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
}

View file

@ -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)
}