mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Refactor regex pattern caching using computeIfAbsent
Closes gh-36755
Signed-off-by: shenjianeng <ishenjianeng@qq.com>
(cherry picked from commit ec21dc0f91)
This commit is contained in:
+4
-6
@@ -98,12 +98,10 @@ public class OperatorMatches extends Operator {
|
||||
}
|
||||
|
||||
try {
|
||||
Pattern pattern = this.patternCache.get(regex);
|
||||
if (pattern == null) {
|
||||
checkRegexLength(regex);
|
||||
pattern = Pattern.compile(regex);
|
||||
this.patternCache.putIfAbsent(regex, pattern);
|
||||
}
|
||||
Pattern pattern = this.patternCache.computeIfAbsent(regex, key -> {
|
||||
checkRegexLength(key);
|
||||
return Pattern.compile(key);
|
||||
});
|
||||
Matcher matcher = pattern.matcher(new MatcherInput(input, new AccessCount()));
|
||||
return BooleanTypedValue.forValue(matcher.matches());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user