Skip to content

Commit ec21dc0

Browse files
shenjianengsbrannen
authored andcommitted
Refactor regex pattern caching using computeIfAbsent
Closes gh-36755 Signed-off-by: shenjianeng <ishenjianeng@qq.com>
1 parent 628261d commit ec21dc0

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,10 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
9898
}
9999

100100
try {
101-
Pattern pattern = this.patternCache.get(regex);
102-
if (pattern == null) {
103-
checkRegexLength(regex);
104-
pattern = Pattern.compile(regex);
105-
this.patternCache.putIfAbsent(regex, pattern);
106-
}
101+
Pattern pattern = this.patternCache.computeIfAbsent(regex, key -> {
102+
checkRegexLength(key);
103+
return Pattern.compile(key);
104+
});
107105
Matcher matcher = pattern.matcher(new MatcherInput(input, new AccessCount()));
108106
return BooleanTypedValue.forValue(matcher.matches());
109107
}

0 commit comments

Comments
 (0)