Skip to content

Commit fd78506

Browse files
committed
pkg/result/processors: compile nolint regexp only once
`regexp.MatchString` compiles regexp for every invocation, there is no pattern caching there. This change introduces a precompiled regexp to save some time while checking comments for nolint directives. Found using go-perfguard with cpu profile collected while running golangci-lint on itself.
1 parent eaed228 commit fd78506

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pkg/result/processors/nolint.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,11 @@ func (p *Nolint) extractFileCommentsInlineRanges(fset *token.FileSet, comments .
232232
return ret
233233
}
234234

235+
var nolintRe = regexp.MustCompile(`^nolint( |:|$)`)
236+
235237
func (p *Nolint) extractInlineRangeFromComment(text string, g ast.Node, fset *token.FileSet) *ignoredRange {
236238
text = strings.TrimLeft(text, "/ ")
237-
if ok, _ := regexp.MatchString(`^nolint( |:|$)`, text); !ok {
239+
if !nolintRe.MatchString(text) {
238240
return nil
239241
}
240242

0 commit comments

Comments
 (0)