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

FindResourceWriters often creates HashSets and ArrayLists while not necessary #34209

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
Expand Down Expand Up @@ -164,7 +163,7 @@ protected List<ResourceWriter> findResourceWriters(QuarkusMultivaluedMap<Class<?
List<ResourceWriter> ret = new ArrayList<>();
Deque<Class<?>> toProcess = new LinkedList<>();
do {
if (currentClass == Object.class) {
if (currentClass == Object.class && !toProcess.isEmpty()) {
//spec extension, look for interfaces as well
//we match interfaces before Object
Set<Class<?>> seen = new HashSet<>(toProcess);
Expand All @@ -182,13 +181,16 @@ protected List<ResourceWriter> findResourceWriters(QuarkusMultivaluedMap<Class<?
}
List<ResourceWriter> goodTypeWriters = writers.get(currentClass);
writerLookup(runtimeType, produces, desired, ret, goodTypeWriters);
toProcess.addAll(Arrays.asList(currentClass.getInterfaces()));
var prevClass = currentClass;
// if we're an interface, pretend our superclass is Object to get us through the same logic as a class
if (currentClass.isInterface()) {
currentClass = Object.class;
} else {
currentClass = currentClass.getSuperclass();
}
if (currentClass != null) {
toProcess.addAll(List.of(prevClass.getInterfaces()));
}
} while (currentClass != null);

return ret;
Expand Down