Browse Source

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>
pull/35665/head
Kamil Krzywanski 2 months ago committed by Sam Brannen
parent
commit
948367092c
  1. 5
      spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java
  2. 3
      spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java
  3. 4
      spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java
  4. 7
      spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java
  5. 4
      spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationsCollection.java
  6. 4
      spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java

5
spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

@ -76,7 +76,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* supplied by the advisors. * supplied by the advisors.
*/ */
public static final TargetSource EMPTY_TARGET_SOURCE = EmptyTargetSource.INSTANCE; 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. */ /** Package-protected to allow direct access for efficiency. */
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ -288,7 +289,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
@Override @Override
public final Advisor[] getAdvisors() { public final Advisor[] getAdvisors() {
return this.advisors.toArray(new Advisor[0]); return this.advisors.toArray(EMPTY_ADVISORS);
} }
@Override @Override

3
spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java

@ -39,6 +39,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Serializable { public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Serializable {
private static final MethodInterceptor [] EMPTY_INTERCEPTOR_ARRAY = new MethodInterceptor[0];
private final List<AdvisorAdapter> adapters = new ArrayList<>(3); private final List<AdvisorAdapter> adapters = new ArrayList<>(3);
@ -89,7 +90,7 @@ public class DefaultAdvisorAdapterRegistry implements AdvisorAdapterRegistry, Se
if (interceptors.isEmpty()) { if (interceptors.isEmpty()) {
throw new UnknownAdviceTypeException(advisor.getAdvice()); throw new UnknownAdviceTypeException(advisor.getAdvice());
} }
return interceptors.toArray(new MethodInterceptor[0]); return interceptors.toArray(EMPTY_INTERCEPTOR_ARRAY);
} }
@Override @Override

4
spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java

@ -44,6 +44,8 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class MutablePropertyValues implements PropertyValues, Serializable { public class MutablePropertyValues implements PropertyValues, Serializable {
private static final PropertyValue[] EMPTY_PROPERTY_VALUES = new PropertyValue[0];
private final List<PropertyValue> propertyValueList; private final List<PropertyValue> propertyValueList;
private @Nullable Set<String> processedProperties; private @Nullable Set<String> processedProperties;
@ -264,7 +266,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
@Override @Override
public PropertyValue[] getPropertyValues() { public PropertyValue[] getPropertyValues() {
return this.propertyValueList.toArray(new PropertyValue[0]); return this.propertyValueList.toArray(EMPTY_PROPERTY_VALUES);
} }
@Override @Override

7
spring-beans/src/main/java/org/springframework/beans/factory/parsing/BeanComponentDefinition.java

@ -37,6 +37,9 @@ import org.springframework.beans.factory.config.BeanReference;
*/ */
public class BeanComponentDefinition extends BeanDefinitionHolder implements ComponentDefinition { 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 BeanDefinition[] innerBeanDefinitions;
private final BeanReference[] beanReferences; private final BeanReference[] beanReferences;
@ -84,8 +87,8 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com
references.add(beanRef); references.add(beanRef);
} }
} }
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]); this.innerBeanDefinitions = innerBeans.toArray(EMPTY_BEAN_DEFINITIONS);
this.beanReferences = references.toArray(new BeanReference[0]); this.beanReferences = references.toArray(EMPTY_BEAN_REFERENCES);
} }

4
spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationsCollection.java

@ -40,6 +40,8 @@ import org.springframework.util.Assert;
*/ */
final class MergedAnnotationsCollection implements MergedAnnotations { final class MergedAnnotationsCollection implements MergedAnnotations {
private static final MergedAnnotation<?> [] EMPTY_ANNOTATIONS = new MergedAnnotation<?>[0];
private final MergedAnnotation<?>[] annotations; private final MergedAnnotation<?>[] annotations;
private final AnnotationTypeMappings[] mappings; private final AnnotationTypeMappings[] mappings;
@ -47,7 +49,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations {
private MergedAnnotationsCollection(Collection<MergedAnnotation<?>> annotations) { private MergedAnnotationsCollection(Collection<MergedAnnotation<?>> annotations) {
Assert.notNull(annotations, "Annotations must not be null"); 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]; this.mappings = new AnnotationTypeMappings[this.annotations.length];
for (int i = 0; i < this.annotations.length; i++) { for (int i = 0; i < this.annotations.length; i++) {
MergedAnnotation<?> annotation = this.annotations[i]; MergedAnnotation<?> annotation = this.annotations[i];

4
spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java

@ -44,6 +44,8 @@ import org.springframework.util.Assert;
*/ */
public abstract class TemplateAwareExpressionParser implements ExpressionParser { public abstract class TemplateAwareExpressionParser implements ExpressionParser {
private static final Expression [] EMPTY_EXPRESSION_ARRAY = new Expression[0];
@Override @Override
public Expression parseExpression(String expressionString) throws ParseException { public Expression parseExpression(String expressionString) throws ParseException {
return parseExpression(expressionString, null); 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);
} }
/** /**

Loading…
Cancel
Save