mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
sort only once for slice
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user