Improve performance of JdkDynamicAopProxy.getProxy()
This commit is contained in:
committed by
Juergen Hoeller
parent
7bc8035989
commit
a033660425
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,6 +57,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @author Dave Syer
|
||||
* @author Sergey Tsypanov
|
||||
* @see java.lang.reflect.Proxy
|
||||
* @see AdvisedSupport
|
||||
* @see ProxyFactory
|
||||
@@ -82,6 +83,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
/** Config used to configure this proxy. */
|
||||
private final AdvisedSupport advised;
|
||||
|
||||
private final Class<?>[] proxiedInterfaces;
|
||||
|
||||
/**
|
||||
* Is the {@link #equals} method defined on the proxied interfaces?
|
||||
*/
|
||||
@@ -105,6 +108,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
throw new AopConfigException("No advisors and no TargetSource specified");
|
||||
}
|
||||
this.advised = config;
|
||||
this.proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised, true);
|
||||
findDefinedEqualsAndHashCodeMethods(this.proxiedInterfaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,9 +123,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Creating JDK dynamic proxy: " + this.advised.getTargetSource());
|
||||
}
|
||||
Class<?>[] proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised, true);
|
||||
findDefinedEqualsAndHashCodeMethods(proxiedInterfaces);
|
||||
return Proxy.newProxyInstance(classLoader, proxiedInterfaces, this);
|
||||
return Proxy.newProxyInstance(classLoader, this.proxiedInterfaces, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -505,12 +505,15 @@ public abstract class ReflectionUtils {
|
||||
* @see java.lang.Object#equals(Object)
|
||||
*/
|
||||
public static boolean isEqualsMethod(@Nullable Method method) {
|
||||
if (method == null || !method.getName().equals("equals")) {
|
||||
if (method == null) {
|
||||
return false;
|
||||
}
|
||||
if (method.getParameterCount() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (!method.getName().equals("equals")) {
|
||||
return false;
|
||||
}
|
||||
return method.getParameterTypes()[0] == Object.class;
|
||||
}
|
||||
|
||||
@@ -519,7 +522,7 @@ public abstract class ReflectionUtils {
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
public static boolean isHashCodeMethod(@Nullable Method method) {
|
||||
return (method != null && method.getName().equals("hashCode") && method.getParameterCount() == 0);
|
||||
return method != null && method.getParameterCount() == 0 && method.getName().equals("hashCode");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -527,7 +530,7 @@ public abstract class ReflectionUtils {
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public static boolean isToStringMethod(@Nullable Method method) {
|
||||
return (method != null && method.getName().equals("toString") && method.getParameterCount() == 0);
|
||||
return (method != null && method.getParameterCount() == 0 && method.getName().equals("toString"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user