From 166511374246f49b18350c0f846799ebaadc7d30 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 27 Nov 2014 22:33:17 +0200 Subject: [PATCH] small optimizations for cache --- cache2go/store.go | 14 ++++---------- engine/ratingprofile.go | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/cache2go/store.go b/cache2go/store.go index 0c6fd9880..3550164c7 100644 --- a/cache2go/store.go +++ b/cache2go/store.go @@ -43,10 +43,7 @@ func (cs cacheDoubleStore) Append(key string, value interface{}) { } else { elements = make(map[interface{}]struct{}) } - // check if the val is already present - if _, found := elements[value]; !found { - elements[value] = struct{}{} - } + elements[value] = struct{}{} cache.Put(key, elements) } @@ -82,8 +79,8 @@ func (cs cacheDoubleStore) DeletePrefix(prefix string) { } func (cs cacheDoubleStore) CountEntriesForPrefix(prefix string) int { - if _, ok := cs[prefix]; ok { - return len(cs[prefix]) + if m, ok := cs[prefix]; ok { + return len(m) } return 0 } @@ -135,10 +132,7 @@ func (cs cacheSimpleStore) Append(key string, value interface{}) { } else { elements = make(map[interface{}]struct{}) } - // check if the val is already present - if _, found := elements[value]; !found { - elements[value] = struct{}{} - } + elements[value] = struct{}{} cache.Put(key, elements) } diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index 6fc886ecb..b9959bcad 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -128,7 +128,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error) for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) { if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil { destIds := x.(map[interface{}]struct{}) - for idId, _ := range destIds { + for idId := range destIds { dId := idId.(string) if _, ok := rpl.DestinationRates[dId]; ok { rps = rpl.RateIntervalList(dId)