From 6631f27b087cf01f57988a4c2747425bd143baed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Insaurralde?= Date: Fri, 27 Mar 2026 22:11:06 -0300 Subject: [PATCH] patchutil: pre-compile splitFormatPatch regex at package init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matías Insaurralde --- patchutil/patchutil.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patchutil/patchutil.go b/patchutil/patchutil.go index 046eeddf..90c81ad7 100644 --- a/patchutil/patchutil.go +++ b/patchutil/patchutil.go @@ -47,6 +47,8 @@ var ( EmptyPatchError error = errors.New("patch is empty") GenericPatchError error = errors.New("patch is invalid") FormatPatchError error = errors.New("patch is not a valid format-patch") + + formatPatchSplitRe = regexp.MustCompile(`(?m)^From [0-9a-f]{40} .*$`) ) func IsPatchValid(patch string) error { @@ -115,9 +117,7 @@ func IsFormatPatch(patch string) bool { } func splitFormatPatch(patchText string) []string { - re := regexp.MustCompile(`(?m)^From [0-9a-f]{40} .*$`) - - indexes := re.FindAllStringIndex(patchText, -1) + indexes := formatPatchSplitRe.FindAllStringIndex(patchText, -1) if len(indexes) == 0 { return []string{} -- 2.51.2