Skip to content

Commit

Permalink
pkg/result/processors: compile nolint regexp only once
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
quasilyte committed Jan 6, 2022
1 parent eaed228 commit fd78506
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/result/processors/nolint.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ func (p *Nolint) extractFileCommentsInlineRanges(fset *token.FileSet, comments .
return ret
}

var nolintRe = regexp.MustCompile(`^nolint( |:|$)`)

func (p *Nolint) extractInlineRangeFromComment(text string, g ast.Node, fset *token.FileSet) *ignoredRange {
text = strings.TrimLeft(text, "/ ")
if ok, _ := regexp.MatchString(`^nolint( |:|$)`, text); !ok {
if !nolintRe.MatchString(text) {
return nil
}

Expand Down

0 comments on commit fd78506

Please sign in to comment.