Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed checker cache optimization. #9

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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