Skip to content

Commit 12ac0c9

Browse files
Herrtiantengtian
andauthored
perf: pre-compile regex in RegexMatch using cached compilation (#1721)
RegexMatch() called regexp.MatchString() which recompiles the pattern on every invocation. Use the existing mustCompileOrGet() cache instead. Ref #1690 Co-authored-by: tengtian <tengtianmoemoe@gamil,com>
1 parent 16b0c89 commit 12ac0c9

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

util/builtin_operators.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ func KeyMatch5Func(args ...interface{}) (interface{}, error) {
332332

333333
// RegexMatch determines whether key1 matches the pattern of key2 in regular expression.
334334
func RegexMatch(key1 string, key2 string) bool {
335-
res, err := regexp.MatchString(key2, key1)
336-
if err != nil {
337-
panic(err)
338-
}
339-
return res
335+
return mustCompileOrGet(key2).MatchString(key1)
340336
}
341337

342338
// RegexMatchFunc is the wrapper for RegexMatch.

0 commit comments

Comments
 (0)