提交 4cd635e9 编写于 作者: S Sam Brannen

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
上级 5105b74f
......@@ -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 {
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 {
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 {
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 {
}
/**
* Marker for autowired arguments in a cached argument array.
*/
private static class AutowiredArgumentMarker {
}
/**
* Delegate for checking Java 6's {@link ConstructorProperties} annotation.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册