diff --git a/callbacks.go b/callbacks.go index 54a4be8575..79eef6d39a 100644 --- a/callbacks.go +++ b/callbacks.go @@ -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 } } - if len(removed) > 0 { - callbacks = removeCallbacks(callbacks, removed) + if len(removedMap) > 0 { + callbacks = removeCallbacks(callbacks, removedMap) } p.callbacks = callbacks @@ -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)