Skip to content

Commit

Permalink
[Performance] Full build takes more time since 2024-09 (type inference)
Browse files Browse the repository at this point in the history
(eclipse-jdt#3384)

optimize 3:
+ never visit the same super type more than once

Fixes eclipse-jdt#3327
  • Loading branch information
stephan-herrmann committed Dec 3, 2024
1 parent 400bddd commit 68514d4
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1264,8 +1264,14 @@ private boolean superOnlyRaw(TypeBinding g, TypeBinding s, LookupEnvironment env
}

protected List<Pair<TypeBinding>> allSuperPairsWithCommonGenericType(TypeBinding s, TypeBinding t) {
return allSuperPairsWithCommonGenericTypeRecursive(s, t, new HashSet<>());
}

private List<Pair<TypeBinding>> allSuperPairsWithCommonGenericTypeRecursive(TypeBinding s, TypeBinding t, HashSet<TypeBinding> visited) {
if (s == null || s.id == TypeIds.T_JavaLangObject || t == null || t.id == TypeIds.T_JavaLangObject)
return Collections.emptyList();
if (!visited.add(s.prototype()))
return Collections.emptyList();
List<Pair<TypeBinding>> result = new ArrayList<>();
if (s.isParameterizedType() && t.isParameterizedType() // optimization #1: clients of this method only want to compare type arguments
&& TypeBinding.equalsEquals(s.original(), t.original())) {
Expand All @@ -1277,11 +1283,11 @@ protected List<Pair<TypeBinding>> allSuperPairsWithCommonGenericType(TypeBinding
if (tSuper != null && s.isParameterizedType() && tSuper.isParameterizedType()) { // optimization #1 again
result.add(new Pair<>(s, tSuper));
}
result.addAll(allSuperPairsWithCommonGenericType(s.superclass(), t));
result.addAll(allSuperPairsWithCommonGenericTypeRecursive(s.superclass(), t, visited));
ReferenceBinding[] superInterfaces = s.superInterfaces();
if (superInterfaces != null) {
for (ReferenceBinding superInterface : superInterfaces) {
result.addAll(allSuperPairsWithCommonGenericType(superInterface, t));
result.addAll(allSuperPairsWithCommonGenericTypeRecursive(superInterface, t, visited));
}
}
return result;
Expand Down

0 comments on commit 68514d4

Please sign in to comment.