Skip to content

Commit

Permalink
Simplify code by not calling Set.contains() before add() (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
mebigfatguy authored Jan 1, 2024
1 parent e56ebae commit 6095105
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Release notes:
1.7.0 (not yet released)

#75: Move JDK baseline to Java 8
(contributed by Dave B, @mebigfatguy)
#83: Simplify code by not calling `Set.contains()` before `add()`
- Remove `Automatic-Module-Name` since we provide proper module-info

1.6.0 (10-Oct-2023)
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/fasterxml/classmate/MemberResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ public ResolvedTypeWithMembers resolve(final ResolvedType mainType,
private void _addOverrides(List<HierarchicType> typesWithOverrides, Set<ClassKey> seenTypes, Class<?> override)
{
ClassKey key = new ClassKey(override);
if (!seenTypes.contains(key)) {
seenTypes.add(key);
if (seenTypes.add(key)) {
ResolvedType resolvedOverride = _typeResolver.resolve(override);
typesWithOverrides.add(new HierarchicType(resolvedOverride, true, typesWithOverrides.size()));
for (ResolvedType r : resolvedOverride.getImplementedInterfaces()) { // interfaces?
Expand All @@ -194,8 +193,7 @@ private void _addOverrides(List<HierarchicType> typesWithOverrides, Set<ClassKey
Class<?> raw = override.getErasedType();
if (!_cfgIncludeLangObject && Object.class == raw) return;
ClassKey key = new ClassKey(raw);
if (!seenTypes.contains(key)) {
seenTypes.add(key);
if (seenTypes.add(key)) {
typesWithOverrides.add(new HierarchicType(override, true, typesWithOverrides.size()));
for (ResolvedType r : override.getImplementedInterfaces()) { // interfaces?
_addOverrides(typesWithOverrides, seenTypes, r);
Expand Down Expand Up @@ -227,11 +225,10 @@ protected void _gatherTypes(ResolvedType currentType, Set<ClassKey> seenTypes,
}
// Finally, only include first instance of an interface, so:
ClassKey key = new ClassKey(currentType.getErasedType());
if (seenTypes.contains(key)) {
if (!seenTypes.add(key)) {
return;
}
// If all good so far, append
seenTypes.add(key);
types.add(currentType);
/* and check supertypes; starting with interfaces. Why interfaces?
* So that "highest" interfaces get priority; otherwise we'd recurse
Expand Down

0 comments on commit 6095105

Please sign in to comment.