Skip to content

Commit

Permalink
reduce number of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
snackmgmg committed Mar 20, 2024
1 parent 8abaddf commit 709c48d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,20 @@ func (p *processor) Replace(name string, fn func(*DB)) error {

func (p *processor) compile() (err error) {
var (
callbacks []*callback
removed []string
callbacks []*callback
removedMap map[string]bool
)
for _, callback := range p.callbacks {
if callback.match == nil || callback.match(p.db) {
callbacks = append(callbacks, callback)
}
if callback.remove {
removed = append(removed, callback.name)
removedMap[callback.name] = true

Check failure on line 198 in callbacks.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

[golangci] reported by reviewdog 🐶 SA5000: assignment to nil map (staticcheck) Raw Output: callbacks.go:198:4: SA5000: assignment to nil map (staticcheck) removedMap[callback.name] = true ^
}
}

if len(removed) > 0 {
callbacks = removeCallbacks(callbacks, removed)
if len(removedMap) > 0 {
callbacks = removeCallbacks(callbacks, removedMap)
}

p.callbacks = callbacks
Expand Down Expand Up @@ -351,10 +351,10 @@ func sortCallbacks(cs []*callback) (fns []func(*DB), err error) {
return
}

func removeCallbacks(cs []*callback, names []string) []*callback {
func removeCallbacks(cs []*callback, nameMap map[string]bool) []*callback {
callbacks := make([]*callback, 0, len(cs))
for _, callback := range cs {
if utils.Contains(names, callback.name) {
if nameMap[callback.name] {
continue
}
callbacks = append(callbacks, callback)
Expand Down

0 comments on commit 709c48d

Please sign in to comment.