Skip to content

Commit

Permalink
Improve equals check by caching resolved generics.
Browse files Browse the repository at this point in the history
Closes: #2974
  • Loading branch information
mp911de authored and christophstrobl committed Nov 9, 2023
1 parent 633d125 commit 65c537c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/main/java/org/springframework/data/util/TypeDiscoverer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
private final Map<Constructor<?>, List<TypeInformation<?>>> constructorParameters = new ConcurrentHashMap<>();
private final Lazy<List<TypeInformation<?>>> typeArguments;

private final Lazy<List<Class>> resolvedGenerics;

protected TypeDiscoverer(ResolvableType type) {

Assert.notNull(type, "Type must not be null");
Expand All @@ -68,6 +70,8 @@ protected TypeDiscoverer(ResolvableType type) {
this.componentType = Lazy.of(this::doGetComponentType);
this.valueType = Lazy.of(this::doGetMapValueType);
this.typeArguments = Lazy.of(this::doGetTypeArguments);
this.resolvedGenerics = Lazy.of(() -> Arrays.stream(resolvableType.getGenerics()) //
.map(ResolvableType::toClass).collect(Collectors.toList()));
}

static TypeDiscoverer<?> td(ResolvableType type) {
Expand Down Expand Up @@ -325,15 +329,7 @@ public boolean equals(@Nullable Object o) {
return false;
}

var collect1 = Arrays.stream(resolvableType.getGenerics()) //
.map(ResolvableType::toClass) //
.collect(Collectors.toList());

var collect2 = Arrays.stream(that.resolvableType.getGenerics()) //
.map(ResolvableType::toClass) //
.collect(Collectors.toList());

return ObjectUtils.nullSafeEquals(collect1, collect2);
return ObjectUtils.nullSafeEquals(resolvedGenerics.get(), that.resolvedGenerics.get());
}

@Override
Expand Down

0 comments on commit 65c537c

Please sign in to comment.