From a218e99e64f1fa1f609bfcec62c67c4f47ac6199 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 6 Apr 2023 19:10:04 +0200 Subject: pkg/email: move patch regexps to globals There's no need to re-initialize them every time. --- pkg/email/patch.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'pkg/email/patch.go') diff --git a/pkg/email/patch.go b/pkg/email/patch.go index c77d19bed..67ea9005a 100644 --- a/pkg/email/patch.go +++ b/pkg/email/patch.go @@ -39,14 +39,15 @@ func ParsePatch(message []byte) (diff string) { return } +var diffRegexps = []*regexp.Regexp{ + regexp.MustCompile(`^(---|\+\+\+) [^\s]`), + regexp.MustCompile(`^diff --git`), + regexp.MustCompile(`^index [0-9a-f]+\.\.[0-9a-f]+`), + regexp.MustCompile(`^new file mode [0-9]+`), + regexp.MustCompile(`^Index: [^\s]`), +} + func lineMatchesDiffStart(ln string) bool { - diffRegexps := []*regexp.Regexp{ - regexp.MustCompile(`^(---|\+\+\+) [^\s]`), - regexp.MustCompile(`^diff --git`), - regexp.MustCompile(`^index [0-9a-f]+\.\.[0-9a-f]+`), - regexp.MustCompile(`^new file mode [0-9]+`), - regexp.MustCompile(`^Index: [^\s]`), - } for _, re := range diffRegexps { if re.MatchString(ln) { return true -- cgit mrf-deployment