Skip to content

Commit d833d04

Browse files
perf(formatters): hoist SCP git URL regex to package level in IsValidGitURL
Move regexp.MustCompile for SCP-style git URLs out of IsValidGitURL so the pattern is compiled once at init instead of on every call. Signed-off-by: Matías Insaurralde <matias@insaurral.de>
1 parent f8df65b commit d833d04

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

formatters/sarif/sarif.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/owenrumney/go-sarif/v2/sarif"
1717
)
1818

19+
var sshPattern = regexp.MustCompile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9._-]+:[a-zA-Z0-9/._-]+$`)
20+
1921
func NewFormat(out io.Writer, version string) *Format {
2022
return &Format{
2123
out: out,
@@ -196,6 +198,5 @@ func IsValidGitURL(gitURL string) bool {
196198
return parsedURL.Host != "" && parsedURL.Path != ""
197199
}
198200

199-
sshPattern := regexp.MustCompile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9._-]+:[a-zA-Z0-9/._-]+$`)
200201
return sshPattern.MatchString(gitURL)
201202
}

0 commit comments

Comments
 (0)