From 6a6d6d6e31bf05bbc94dbf060a2e4afb51d92806 Mon Sep 17 00:00:00 2001 From: quobix Date: Thu, 9 Nov 2023 06:27:58 -0500 Subject: [PATCH] Moved regex to precompile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I don’t know why I put this in the hotpath. Signed-off-by: quobix --- utils/utils.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index fe6cc4b..1370241 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -713,10 +713,11 @@ func CheckEnumForDuplicates(seq []*yaml.Node) []*yaml.Node { return res } +var whitespaceExp = regexp.MustCompile(`\n( +)`) + // DetermineWhitespaceLength will determine the length of the whitespace for a JSON or YAML file. func DetermineWhitespaceLength(input string) int { - exp := regexp.MustCompile(`\n( +)`) - whiteSpace := exp.FindAllStringSubmatch(input, -1) + whiteSpace := whitespaceExp.FindAllStringSubmatch(input, -1) var filtered []string for i := range whiteSpace { filtered = append(filtered, whiteSpace[i][1])