Remove std sort and use custom sort for performances

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)
Upstream-commit: da30eb7c2038c8c554e1f44c80c061c7a827a429
Component: engine
This commit is contained in:
Guillaume J. Charmes
2014-01-23 17:35:39 -08:00
committed by Michael Crosby
parent c104696fd4
commit ad36af979f

View File

@ -1,7 +1,6 @@
package collections
import (
"sort"
"sync"
)
@ -28,9 +27,17 @@ func (s *OrderedIntSet) Push(elem int) {
s.RUnlock()
s.Lock()
s.set = append(s.set, elem)
// Make sure the list is always sorted
sort.Ints(s.set)
for i, e := range s.set {
if elem < e {
s.set = append(s.set[:i], append([]int{elem}, s.set[i:]...)...)
s.Unlock()
return
}
}
// If we reach here, then elem is the biggest elem of the list.
s.set = append(s.set, elem)
s.Unlock()
}