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)
This commit is contained in:
parent
560481026d
commit
af411bf9d5
1 changed files with 10 additions and 3 deletions
|
@ -1,7 +1,6 @@
|
||||||
package collections
|
package collections
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,9 +27,17 @@ func (s *OrderedIntSet) Push(elem int) {
|
||||||
s.RUnlock()
|
s.RUnlock()
|
||||||
|
|
||||||
s.Lock()
|
s.Lock()
|
||||||
s.set = append(s.set, elem)
|
|
||||||
// Make sure the list is always sorted
|
// 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()
|
s.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue