Browse Source

Avoid repeated instantiation of AutowiredArgumentMarker

Prior to this commit, the AutowiredArgumentMarker type was repeatedly
instantiated in ConstructorResolver.

This commit replaces the AutowiredArgumentMarker type with a simple
Object instance.

Closes gh-23469
pull/23519/head
Sam Brannen 6 years ago
parent
commit
4cd635e9c8
  1. 21
      spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

21
spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

@ -66,13 +66,14 @@ import org.springframework.util.StringUtils; @@ -66,13 +66,14 @@ import org.springframework.util.StringUtils;
/**
* Delegate for resolving constructors and factory methods.
* Performs constructor resolution through argument matching.
* <p>Performs constructor resolution through argument matching.
*
* @author Juergen Hoeller
* @author Rob Harrop
* @author Mark Fisher
* @author Costin Leau
* @author Sebastien Deleuze
* @author Sam Brannen
* @since 2.0
* @see #autowireConstructor
* @see #instantiateUsingFactoryMethod
@ -82,9 +83,16 @@ class ConstructorResolver { @@ -82,9 +83,16 @@ class ConstructorResolver {
private static final Object[] EMPTY_ARGS = new Object[0];
/**
* Marker for autowired arguments in a cached argument array, to be later replaced
* by a {@linkplain #resolveAutowiredArgument resolved autowired argument}.
*/
private static final Object autowiredArgumentMarker = new Object();
private static final NamedThreadLocal<InjectionPoint> currentInjectionPoint =
new NamedThreadLocal<>("Current injection point");
private final AbstractAutowireCapableBeanFactory beanFactory;
private final Log logger;
@ -771,7 +779,7 @@ class ConstructorResolver { @@ -771,7 +779,7 @@ class ConstructorResolver {
methodParam, beanName, autowiredBeanNames, converter, fallback);
args.rawArguments[paramIndex] = autowiredArgument;
args.arguments[paramIndex] = autowiredArgument;
args.preparedArguments[paramIndex] = new AutowiredArgumentMarker();
args.preparedArguments[paramIndex] = autowiredArgumentMarker;
args.resolveNecessary = true;
}
catch (BeansException ex) {
@ -809,7 +817,7 @@ class ConstructorResolver { @@ -809,7 +817,7 @@ class ConstructorResolver {
for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
Object argValue = argsToResolve[argIndex];
MethodParameter methodParam = MethodParameter.forExecutable(executable, argIndex);
if (argValue instanceof AutowiredArgumentMarker) {
if (argValue == autowiredArgumentMarker) {
argValue = resolveAutowiredArgument(methodParam, beanName, null, converter, fallback);
}
else if (argValue instanceof BeanMetadataElement) {
@ -963,13 +971,6 @@ class ConstructorResolver { @@ -963,13 +971,6 @@ class ConstructorResolver {
}
/**
* Marker for autowired arguments in a cached argument array.
*/
private static class AutowiredArgumentMarker {
}
/**
* Delegate for checking Java 6's {@link ConstructorProperties} annotation.
*/

Loading…
Cancel
Save