sort only once for slice

This commit is contained in:
Radu Ioan Fericean
2014-11-26 17:44:32 +02:00
parent 72c3d1ac29
commit 728354331b
2 changed files with 2 additions and 1 deletions

View File

@@ -20,6 +20,7 @@ package engine
import (
"encoding/json"
"sort"
"strings"
"github.com/cgrates/cgrates/cache2go"
@@ -92,6 +93,7 @@ func CleanStalePrefixes(destIds []string) {
for prefix, idIDs := range prefixMap {
dIDs := idIDs.Value().([]interface{})
changed := false
sort.Sort(utils.InterfaceStrings(dIDs))
for _, searchedDID := range destIds {
if i, found := utils.GetSliceInterfaceIndex(dIDs, searchedDID); found {
if len(dIDs) == 1 {

View File

@@ -61,7 +61,6 @@ func (a InterfaceStrings) Less(i, j int) bool { return a[i].(string) < a[j].(str
// Binary string search in slice
// returns true if found and the index
func GetSliceInterfaceIndex(ss []interface{}, s interface{}) (int, bool) {
sort.Sort(InterfaceStrings(ss))
if i := sort.Search(len(ss), func(i int) bool { return ss[i].(string) >= s.(string) }); i < len(ss) && ss[i] == s {
return i, true
}