Skip to content

Commit

Permalink
ArC: reduce retained memory by RemovedBeanImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Jul 2, 2021
1 parent 6876ec0 commit 6f262c9
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.quarkus.arc.RemovedBean;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public final class RemovedBeanImpl implements RemovedBean {
Expand All @@ -12,18 +14,20 @@ public final class RemovedBeanImpl implements RemovedBean {
* Implementation note: this class needs to be optimised to
* minimize the size of retained memory: runtime efficiency is less important.
*/
private static final Type[] EMPTY_TYPES = new Type[] {};
private static final Annotation[] EMPTY_QUALIFIERS = new Annotation[] {};
private static final Annotation[] DEFAULT_QUALIFIERS = Qualifiers.DEFAULT_QUALIFIERS.toArray(EMPTY_QUALIFIERS);

private final Kind kind;
private final String description;
private final Set<Type> types;
private final Set<Annotation> qualifiers;
private final Type[] types;
private final Annotation[] qualifiers;

public RemovedBeanImpl(Kind kind, String description, Set<Type> types, Set<Annotation> qualifiers) {
this.kind = kind != null ? kind : Kind.CLASS;
this.description = description;
this.types = CollectionHelpers.toImmutableSmallSet(types);
this.qualifiers = qualifiers != null ? CollectionHelpers.toImmutableSmallSet(qualifiers)
: Qualifiers.DEFAULT_QUALIFIERS;
this.types = types == null ? EMPTY_TYPES : types.toArray(EMPTY_TYPES);
this.qualifiers = qualifiers != null ? qualifiers.toArray(EMPTY_QUALIFIERS) : DEFAULT_QUALIFIERS;
}

@Override
Expand All @@ -38,12 +42,12 @@ public String getDescription() {

@Override
public Set<Type> getTypes() {
return types;
return new HashSet<>(Arrays.asList(types));
}

@Override
public Set<Annotation> getQualifiers() {
return qualifiers;
return new HashSet<>(Arrays.asList(qualifiers));
}

@Override
Expand All @@ -58,20 +62,19 @@ public boolean matchesType(Type requiredType) {

@Override
public Iterable<Annotation> qualifiers() {
return qualifiers;
return Arrays.asList(qualifiers);
}

@Override
public Iterable<Type> types() {
return types;
return Arrays.asList(types);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(kind).append(" bean ").append(description).append(" [types=")
.append(types).append(", qualifiers=").append(qualifiers).append("]");
return builder.toString();
return kind.toString() + " bean " + description +
" [types=" + Arrays.toString(types) +
", qualifiers=" + Arrays.toString(qualifiers) + "]";
}

}

0 comments on commit 6f262c9

Please sign in to comment.