Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid wasted memory on empty maps and sets #29742

Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,20 @@ protected boolean needsRefresh(Class<?> clazz) {
}

public void checkConfigMembers(RootBeanDefinition beanDefinition) {
Set<InjectedElement> checkedElements = new LinkedHashSet<>(this.injectedElements.size());
for (InjectedElement element : this.injectedElements) {
Member member = element.getMember();
if (!beanDefinition.isExternallyManagedConfigMember(member)) {
beanDefinition.registerExternallyManagedConfigMember(member);
checkedElements.add(element);
if (this.injectedElements.isEmpty()) {
this.checkedElements = Set.of();
}
else {
Set<InjectedElement> checkedElements = new LinkedHashSet<>(this.injectedElements.size());
sbrannen marked this conversation as resolved.
Show resolved Hide resolved
for (InjectedElement element : this.injectedElements) {
Member member = element.getMember();
if (!beanDefinition.isExternallyManagedConfigMember(member)) {
beanDefinition.registerExternallyManagedConfigMember(member);
checkedElements.add(element);
}
}
this.checkedElements = checkedElements;
}
this.checkedElements = checkedElements;
}

public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ public AnnotationVisitor visitArray(String name) {

@Override
public void visitEnd() {
Map<String, Object> compactedAttributes
= this.attributes.size() == 0 ? Map.of() : this.attributes;
MergedAnnotation<A> annotation = MergedAnnotation.of(
this.classLoader, this.source, this.annotationType, this.attributes);
this.classLoader, this.source, this.annotationType, compactedAttributes);
this.consumer.accept(annotation);
}

Expand Down