Skip to content

Commit

Permalink
Merge pull request #34209 from franz1981/reduce_gc_find_writers
Browse files Browse the repository at this point in the history
FindResourceWriters often creates HashSets and ArrayLists while not necessary
  • Loading branch information
geoand authored Jul 20, 2023
2 parents e23f434 + ef07212 commit ed2f2a8
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit ed2f2a8

Please sign in to comment.