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:
shenjianeng
2026-05-06 13:55:03 +02:00
committed by Sam Brannen
parent c6b485c31d
commit e8f08b4158
@@ -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());
}