Skip to content

Commit

Permalink
Removed checker cache optimization. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jun 15, 2023
1 parent 0bad7f0 commit e68227c
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ var makers = map[string]MakeFunc{
"required": makeRequired,
}

// checkerCache provides mapping to checker functions for the config.
var checkerCache = map[string]CheckFunc{}

// Register registers the given checker name and the maker function.
func Register(name string, maker MakeFunc) {
makers[name] = maker
Expand Down Expand Up @@ -108,20 +105,14 @@ func initCheckers(config string) []CheckFunc {
checkers := make([]CheckFunc, len(fields))

for i, field := range fields {
checker, ok := checkerCache[field]
if !ok {
name, params, _ := strings.Cut(field, ":")
name, params, _ := strings.Cut(field, ":")

maker, ok := makers[name]
if !ok {
panic(fmt.Sprintf("checker %s is unkown", name))
}

checker = maker(params)
checkerCache[field] = checker
maker, ok := makers[name]
if !ok {
panic(fmt.Sprintf("checker %s is unkown", name))
}

checkers[i] = checker
checkers[i] = maker(params)
}

return checkers
Expand Down

0 comments on commit e68227c

Please sign in to comment.