Skip to content

Commit

Permalink
perf: map make with cap
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshenzzg committed Mar 6, 2024
1 parent 5c033d3 commit 8ffd1cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ func (c *jetCache[K, V]) MGet(ctx context.Context, key string, ids []K, fn func(
c.statsHandler.IncrQueryFail(err)
logger.Error("MGet#fn(%s) error(%v)", util.JoinAny(",", ids), err)
} else {
placeholderValues := make(map[string]any)
cacheValues := make(map[string]any)
placeholderValues := make(map[string]any, len(ids))
cacheValues := make(map[string]any, len(ids))
for rk, rv := range fnValues {
values[rk] = rv
cacheKey := util.JoinAny(":", key, rk)
Expand Down Expand Up @@ -365,8 +365,8 @@ func (c *jetCache[K, V]) MGet(ctx context.Context, key string, ids []K, fn func(
}

func (c *jetCache[K, V]) mGetCache(ctx context.Context, key string, ids []K) (v map[K]V, missIds []K) {
v = make(map[K]V)
miss := make(map[string]K)
v = make(map[K]V, len(ids))
miss := make(map[string]K, len(ids))

for _, id := range ids {
cacheKey := util.JoinAny(":", key, id)
Expand All @@ -393,7 +393,7 @@ func (c *jetCache[K, V]) mGetCache(ctx context.Context, key string, ids []K) (v
}

if len(miss) > 0 && c.remote != nil {
missKeys := make([]string, 0)
missKeys := make([]string, 0, len(miss))
for k := range miss {
missKeys = append(missKeys, k)
}
Expand Down
2 changes: 1 addition & 1 deletion remote/goredisv8adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *GoRedisV8Adaptor) Del(ctx context.Context, key string) (val int64, err
func (r *GoRedisV8Adaptor) MGet(ctx context.Context, keys ...string) (map[string]any, error) {
pipeline := r.client.Pipeline()
keyIdxMap := make(map[int]string, len(keys))
ret := make(map[string]any)
ret := make(map[string]any, len(keys))

for idx, key := range keys {
keyIdxMap[idx] = key
Expand Down

0 comments on commit 8ffd1cf

Please sign in to comment.