This is an automated email from the ASF dual-hosted git repository.
nodece pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin.git
The following commit(s) were added to refs/heads/master by this push:
new 12ac0c9 perf: pre-compile regex in RegexMatch using cached
compilation (#1721)
12ac0c9 is described below
commit 12ac0c9a42e0245be6da0244737309e369aa4869
Author: TT <[email protected]>
AuthorDate: Wed May 6 13:15:36 2026 +0200
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>
---
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 066a0bd..e2c8114 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.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]