Skip to content

Commit 697daa0

Browse files
authored
feat: optimize fast path in convertInSyntax method (#451)
1 parent 677c106 commit 697daa0

File tree

1 file changed

+14
-8
lines changed
  • src/main/java/org/casbin/jcasbin/util

1 file changed

+14
-8
lines changed

src/main/java/org/casbin/jcasbin/util/Util.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,25 @@ public static String escapeAssertion(String s) {
146146
* @return the 'include' expression.
147147
*/
148148
public static String convertInSyntax(String expString) {
149-
Matcher matcher = IN_SYNTAX_PATTERN.matcher(expString);
150-
if (matcher.find()) {
151-
StringBuffer sb = new StringBuffer();
152-
do {
153-
matcher.appendReplacement(sb, "include($2, $1)");
154-
} while (matcher.find());
155-
matcher.appendTail(sb);
156-
return sb.toString();
149+
if (expString.contains(" in ")) {
150+
Matcher matcher = IN_SYNTAX_PATTERN.matcher(expString);
151+
if (matcher.find()) {
152+
return replaceInSyntaxWithInclude(matcher);
153+
}
157154
}
158155

159156
return expString;
160157
}
161158

159+
private static String replaceInSyntaxWithInclude(Matcher matcher) {
160+
StringBuffer sb = new StringBuffer();
161+
do {
162+
matcher.appendReplacement(sb, "include($2, $1)");
163+
} while (matcher.find());
164+
matcher.appendTail(sb);
165+
return sb.toString();
166+
}
167+
162168
/**
163169
* removeComments removes the comments starting with # in the text.
164170
*

0 commit comments

Comments
 (0)