mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Use empty array constants instead of repeatedly creating new ones
Closes gh-35660 Signed-off-by: Kamil Krzywański <kamilkrzywanski01@gmail.com> Signed-off-by: Kamil Krzywanski <kamilkrzywanski01@gmail.com>
This commit is contained in:
committed by
Sam Brannen
parent
687bc7652d
commit
948367092c
@@ -76,7 +76,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
* supplied by the advisors.
|
||||
*/
|
||||
public static final TargetSource EMPTY_TARGET_SOURCE = EmptyTargetSource.INSTANCE;
|
||||
|
||||
/** Empty advisor array constant. */
|
||||
public static final Advisor[] EMPTY_ADVISORS = new Advisor[0];
|
||||
|
||||
/** Package-protected to allow direct access for efficiency. */
|
||||
@SuppressWarnings("serial")
|
||||
@@ -288,7 +289,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
|
||||
@Override
|
||||
public final Advisor[] getAdvisors() {
|
||||
return this.advisors.toArray(new Advisor[0]);
|
||||
return this.advisors.toArray(EMPTY_ADVISORS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -39,6 +39,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Serializable {
|
||||
private static final MethodInterceptor [] EMPTY_INTERCEPTOR_ARRAY = new MethodInterceptor[0];
|
||||
|
||||
private final List<AdvisorAdapter> adapters = new ArrayList<>(3);
|
||||
|
||||
@@ -89,7 +90,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
|
||||
if (interceptors.isEmpty()) {
|
||||
throw new UnknownAdviceTypeException(advisor.getAdvice());
|
||||
}
|
||||
return interceptors.toArray(new MethodInterceptor[0]);
|
||||
return interceptors.toArray(EMPTY_INTERCEPTOR_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.springframework.util.StringUtils;
|
||||
@SuppressWarnings("serial")
|
||||
public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
|
||||
private static final PropertyValue[] EMPTY_PROPERTY_VALUES = new PropertyValue[0];
|
||||
|
||||
private final List<PropertyValue> propertyValueList;
|
||||
|
||||
private @Nullable Set<String> processedProperties;
|
||||
@@ -264,7 +266,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||
|
||||
@Override
|
||||
public PropertyValue[] getPropertyValues() {
|
||||
return this.propertyValueList.toArray(new PropertyValue[0]);
|
||||
return this.propertyValueList.toArray(EMPTY_PROPERTY_VALUES);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-2
@@ -37,6 +37,9 @@ import org.springframework.beans.factory.config.BeanReference;
|
||||
*/
|
||||
public class BeanComponentDefinition extends BeanDefinitionHolder implements ComponentDefinition {
|
||||
|
||||
private static final BeanDefinition[] EMPTY_BEAN_DEFINITIONS = new BeanDefinition[0];
|
||||
private static final BeanReference[] EMPTY_BEAN_REFERENCES = new BeanReference[0];
|
||||
|
||||
private final BeanDefinition[] innerBeanDefinitions;
|
||||
|
||||
private final BeanReference[] beanReferences;
|
||||
@@ -84,8 +87,8 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com
|
||||
references.add(beanRef);
|
||||
}
|
||||
}
|
||||
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
|
||||
this.beanReferences = references.toArray(new BeanReference[0]);
|
||||
this.innerBeanDefinitions = innerBeans.toArray(EMPTY_BEAN_DEFINITIONS);
|
||||
this.beanReferences = references.toArray(EMPTY_BEAN_REFERENCES);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -40,6 +40,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
final class MergedAnnotationsCollection implements MergedAnnotations {
|
||||
|
||||
private static final MergedAnnotation<?> [] EMPTY_ANNOTATIONS = new MergedAnnotation<?>[0];
|
||||
|
||||
private final MergedAnnotation<?>[] annotations;
|
||||
|
||||
private final AnnotationTypeMappings[] mappings;
|
||||
@@ -47,7 +49,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations {
|
||||
|
||||
private MergedAnnotationsCollection(Collection<MergedAnnotation<?>> annotations) {
|
||||
Assert.notNull(annotations, "Annotations must not be null");
|
||||
this.annotations = annotations.toArray(new MergedAnnotation<?>[0]);
|
||||
this.annotations = annotations.toArray(EMPTY_ANNOTATIONS);
|
||||
this.mappings = new AnnotationTypeMappings[this.annotations.length];
|
||||
for (int i = 0; i < this.annotations.length; i++) {
|
||||
MergedAnnotation<?> annotation = this.annotations[i];
|
||||
|
||||
+3
-1
@@ -44,6 +44,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class TemplateAwareExpressionParser implements ExpressionParser {
|
||||
|
||||
private static final Expression [] EMPTY_EXPRESSION_ARRAY = new Expression[0];
|
||||
|
||||
@Override
|
||||
public Expression parseExpression(String expressionString) throws ParseException {
|
||||
return parseExpression(expressionString, null);
|
||||
@@ -136,7 +138,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||
}
|
||||
}
|
||||
|
||||
return expressions.toArray(new Expression[0]);
|
||||
return expressions.toArray(EMPTY_EXPRESSION_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user