From 193a76fe2a8bc3c64fe66528ce863d21e14884a2 Mon Sep 17 00:00:00 2001 From: Qimiao Chen Date: Mon, 16 Mar 2020 19:38:43 +0800 Subject: [PATCH] Avoid unnecessary sorting in AbstractHandlerMethodMapping Closes gh-24704 --- .../web/servlet/handler/AbstractHandlerMethodMapping.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java index 0fbfc988c1..9c94758a16 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java @@ -394,10 +394,11 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } if (!matches.isEmpty()) { - Comparator comparator = new MatchComparator(getMappingComparator(request)); - matches.sort(comparator); Match bestMatch = matches.get(0); if (matches.size() > 1) { + Comparator comparator = new MatchComparator(getMappingComparator(request)); + matches.sort(comparator); + bestMatch = matches.get(0); if (logger.isTraceEnabled()) { logger.trace(matches.size() + " matching mappings: " + matches); }