From da30eb7c2038c8c554e1f44c80c061c7a827a429 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Thu, 23 Jan 2014 17:35:39 -0800 Subject: [PATCH] Remove std sort and use custom sort for performances Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- pkg/collections/orderedintset.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/collections/orderedintset.go b/pkg/collections/orderedintset.go index 456975cbb0..23abab04d3 100644 --- a/pkg/collections/orderedintset.go +++ b/pkg/collections/orderedintset.go @@ -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() }