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

Simplify code by not calling Set.contains() before add() #83

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Changes from 1 commit
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
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