From f4fa290dbe489755e8ec917bc9340525ba85071e Mon Sep 17 00:00:00 2001 From: tengtian Date: Wed, 15 Apr 2026 19:48:43 +0200 Subject: [PATCH] perf: pre-compile regex in RegexMatch using cached compilation RegexMatch() called regexp.MatchString() which recompiles the pattern on every invocation. Use the existing mustCompileOrGet() cache instead. Ref #1690 --- util/builtin_operators.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/util/builtin_operators.go b/util/builtin_operators.go index 37d9cb5bf..4d25fd5fd 100644 --- a/util/builtin_operators.go +++ b/util/builtin_operators.go @@ -332,11 +332,7 @@ func KeyMatch5Func(args ...interface{}) (interface{}, error) { // RegexMatch determines whether key1 matches the pattern of key2 in regular expression. func RegexMatch(key1 string, key2 string) bool { - res, err := regexp.MatchString(key2, key1) - if err != nil { - panic(err) - } - return res + return mustCompileOrGet(key2).MatchString(key1) } // RegexMatchFunc is the wrapper for RegexMatch.