Use computeIfAbsent in SpelCompiler and AdvisedSupport

See gh-26028
This commit is contained in:
hzmpay 2020-11-04 15:00:11 +08:00 committed by Stephane Nicoll
parent 178cb429a8
commit cde476f90e
2 changed files with 3 additions and 13 deletions

View File

@ -479,14 +479,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) * @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
*/ */
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) { public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
MethodCacheKey cacheKey = new MethodCacheKey(method); return this.methodCache.computeIfAbsent(new MethodCacheKey(method), k ->
List<Object> cached = this.methodCache.get(cacheKey); this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(this, method, targetClass));
if (cached == null) {
cached = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
this, method, targetClass);
this.methodCache.put(cacheKey, cached);
}
return cached;
} }
/** /**

View File

@ -233,11 +233,7 @@ public final class SpelCompiler implements Opcodes {
if (compiler == null) { if (compiler == null) {
// Full lock now since we're creating a child ClassLoader // Full lock now since we're creating a child ClassLoader
synchronized (compilers) { synchronized (compilers) {
compiler = compilers.get(clToUse); return compilers.computeIfAbsent(clToUse, SpelCompiler::new);
if (compiler == null) {
compiler = new SpelCompiler(clToUse);
compilers.put(clToUse, compiler);
}
} }
} }
return compiler; return compiler;