Remove unnecessary up traversal from traversePolymorphic.
Only case we need traversal up is rescue a method that become alive due to an accidental override.
@@ -63,7 +63,11 @@ final class RapidTypeAnalyser {
private static void traversePolymorphicReference(Type type, String memberName) {
Member member = type.getMemberByName(memberName);
- if (member != null) {
+ if (member == null) {
+ // No member found in this class. In this case we need to mark the supertype method as
+ // potentially live since it might be an accidental override.
+ markOverriddenMembersPotentiallyLive(type, memberName);
+ } else if (member.isPolymorphic()) {
if (member.isFullyTraversed()) {
return;
}
@@ -75,20 +79,15 @@ final class RapidTypeAnalyser {
// Recursively unfold the overriding chain.
type.getImmediateSubtypes()
.forEach(subtype -> traversePolymorphicReference(subtype, memberName));
-
- markOverriddenMembersPotentiallyLive(type, memberName);
}
private static void markOverriddenMembersPotentiallyLive(Type type, String memberName) {
while ((type = type.getSuperClass()) != null) {
Member member = type.getMemberByName(memberName);
- if (member == null) {
- continue;
- }
- if (!member.isPolymorphic()) {
+ if (member != null && member.isPolymorphic()) {
+ markMemberPotentiallyLive(member);
return;
}
- markMemberPotentiallyLive(member);
}
}
