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:
Christoph Dreis
2016-12-02 12:26:14 +01:00
committed by Oliver Gierke
parent 1ad82cb82d
commit 9b3dd05baa
6 changed files with 8 additions and 9 deletions

View File

@@ -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());

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);
}