DATACMNS-867 - Avoid allocations from Method.getParameterTypes() where possible.
We now prefer an explicit Method.getParameterCount() over accessing the parameter types array and its length to avoid the overhead of cloning the array. Original pull request: #187.
This commit is contained in:
committed by
Oliver Gierke
parent
1ad82cb82d
commit
9b3dd05baa
@@ -246,7 +246,7 @@ class DefaultRepositoryInformation implements RepositoryInformation {
|
||||
|
||||
Supplier<Optional<Method>> detailedComparison = () -> baseClass.flatMap(it -> Arrays.stream(it.getMethods())//
|
||||
.filter(baseClassMethod -> method.getName().equals(baseClassMethod.getName()))// Right name
|
||||
.filter(baseClassMethod -> method.getParameterTypes().length == baseClassMethod.getParameterTypes().length)
|
||||
.filter(baseClassMethod -> method.getParameterCount() == baseClassMethod.getParameterCount())
|
||||
.filter(baseClassMethod -> parametersMatch(method, baseClassMethod))// All parameters match
|
||||
.findFirst());
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ public class ReactiveRepositoryInformation extends DefaultRepositoryInformation
|
||||
|
||||
return Arrays.stream(baseClass.getMethods())//
|
||||
.filter(it -> method.getName().equals(it.getName()))//
|
||||
.filter(it -> method.getParameterTypes().length == it.getParameterTypes().length)//
|
||||
.filter(it -> method.getParameterCount() == it.getParameterCount())//
|
||||
.filter(it -> parametersMatch(it, method, predicate))//
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
@@ -101,12 +101,12 @@ public class Function {
|
||||
*/
|
||||
public boolean supports(List<TypeDescriptor> argumentTypes) {
|
||||
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
|
||||
if (parameterTypes.length != argumentTypes.size()) {
|
||||
if (method.getParameterCount() != argumentTypes.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (!TypeUtils.isAssignable(parameterTypes[i], argumentTypes.get(i).getType())) {
|
||||
return false;
|
||||
|
||||
@@ -60,7 +60,7 @@ class MethodParameters {
|
||||
Assert.notNull(method, "Method must not be null!");
|
||||
this.parameters = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < method.getParameterTypes().length; i++) {
|
||||
for (int i = 0; i < method.getParameterCount(); i++) {
|
||||
|
||||
MethodParameter parameter = new AnnotationNamingMethodParameter(method, i, namingAnnotation);
|
||||
parameter.initParameterNameDiscovery(discoverer);
|
||||
|
||||
@@ -283,9 +283,8 @@ class ReflectionRepositoryInvoker implements RepositoryInvoker {
|
||||
|
||||
Method method = methods.getFindAllMethod()
|
||||
.orElseThrow(() -> new IllegalStateException("Repository doesn't have a find-all-method declared!"));
|
||||
Class<?>[] types = method.getParameterTypes();
|
||||
|
||||
if (types.length == 0) {
|
||||
if (method.getParameterCount() == 0) {
|
||||
return invoke(method);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user