Skip to content

Commit

Permalink
perf: map clear (yomorun#753)
Browse files Browse the repository at this point in the history
# Description

Use the built-in function(clear) to delete all map elements.
  • Loading branch information
venjiang authored Mar 14, 2024
1 parent 0dfc544 commit e30a044
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
4 changes: 1 addition & 3 deletions core/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,5 @@ func (c *Context) reset() {
c.Frame = nil
c.FrameMetadata = nil
c.Logger = nil
for k := range c.Keys {
delete(c.Keys, k)
}
clear(c.Keys)
}
9 changes: 2 additions & 7 deletions core/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ func (r *defaultRouter) Release() {
r.mu.Lock()
defer r.mu.Unlock()

for key := range r.targets {
delete(r.targets, key)
}

for key := range r.data {
delete(r.data, key)
}
clear(r.targets)
clear(r.data)
}
4 changes: 1 addition & 3 deletions pkg/bridge/ai/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ func (s *Service) Release() {
if s.reducer != nil {
s.reducer.Close()
}
// INFO: use clear on go1.21 or later
// clear(s.cache)
s.cache = map[string]*CacheItem{}
clear(s.cache)
}

func (s *Service) createSource() (yomo.Source, error) {
Expand Down

0 comments on commit e30a044

Please sign in to comment.