Browse Source

Improve equals check by caching resolved generics.

Closes: #2974
pull/2978/head
Mark Paluch 2 years ago committed by Christoph Strobl
parent
commit
65c537cdaa
No known key found for this signature in database
GPG Key ID: 8CC1AB53391458C8
  1. 14
      src/main/java/org/springframework/data/util/TypeDiscoverer.java

14
src/main/java/org/springframework/data/util/TypeDiscoverer.java

@ -60,6 +60,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> { @@ -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");
@ -68,6 +70,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> { @@ -68,6 +70,8 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
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) {
@ -325,15 +329,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> { @@ -325,15 +329,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
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

Loading…
Cancel
Save