don't call sort for every add in daemon/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`.

Here are the numbers from a system with 2006 containers:
```
unpatched List() - 183.966515ms
patched List() - 601.514us
305x improvement
```

Fixes #5297