From 92a6ec800c4b83b92c9d1b967812ea3fceff905b Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 27 Oct 2022 09:36:31 +0200 Subject: [PATCH] Polishing. Use for-loop instead of stream to reduce overhead. See #2722 --- .../QueryExecutorMethodInterceptor.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/core/support/QueryExecutorMethodInterceptor.java b/src/main/java/org/springframework/data/repository/core/support/QueryExecutorMethodInterceptor.java index cc1d8f5db..4cb1495e1 100644 --- a/src/main/java/org/springframework/data/repository/core/support/QueryExecutorMethodInterceptor.java +++ b/src/main/java/org/springframework/data/repository/core/support/QueryExecutorMethodInterceptor.java @@ -17,6 +17,7 @@ package org.springframework.data.repository.core.support; import java.lang.reflect.Method; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -78,9 +79,9 @@ class QueryExecutorMethodInterceptor implements MethodInterceptor { if (!queryLookupStrategy.isPresent() && repositoryInformation.hasQueryMethods()) { - throw new IllegalStateException("You have defined query methods in the repository" - + " but do not have any query lookup strategy defined." - + " The infrastructure apparently does not support query methods"); + throw new IllegalStateException( + "You have defined query methods in the repository" + " but do not have any query lookup strategy defined." + + " The infrastructure apparently does not support query methods"); } this.queries = queryLookupStrategy // @@ -91,10 +92,17 @@ class QueryExecutorMethodInterceptor implements MethodInterceptor { private Map mapMethodsToQuery(RepositoryInformation repositoryInformation, QueryLookupStrategy lookupStrategy, ProjectionFactory projectionFactory) { - return repositoryInformation.getQueryMethods().stream() // - .map(method -> lookupQuery(method, repositoryInformation, lookupStrategy, projectionFactory)) // - .peek(pair -> invokeListeners(pair.getSecond())) // - .collect(Pair.toMap()); + Map result = new HashMap<>(); + + for (Method method : repositoryInformation.getQueryMethods()) { + + Pair pair = lookupQuery(method, repositoryInformation, lookupStrategy, + projectionFactory); + invokeListeners(pair.getSecond()); + result.put(pair.getFirst(), pair.getSecond()); + } + + return result; } private Pair lookupQuery(Method method, RepositoryInformation information,