From b807f9f4e996b74ae60c0c990b97a01d1c19be47 Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Tue, 1 Nov 2022 20:04:13 +0100 Subject: [PATCH] Reduce allocations caused by producible media types --- .../result/method/RequestMappingInfoHandlerMapping.java | 9 ++++++--- .../mvc/method/RequestMappingInfoHandlerMapping.java | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java index 60372f716cd3..1a1ee0073aaf 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java @@ -142,9 +142,12 @@ protected void handleMatch(RequestMappingInfo info, HandlerMethod handlerMethod, exchange.getAttributes().put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables); exchange.getAttributes().put(MATRIX_VARIABLES_ATTRIBUTE, matrixVariables); - if (!info.getProducesCondition().getProducibleMediaTypes().isEmpty()) { - Set mediaTypes = info.getProducesCondition().getProducibleMediaTypes(); - exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes); + ProducesRequestCondition producesCondition = info.getProducesCondition(); + if (!producesCondition.isEmpty()) { + Set mediaTypes = producesCondition.getProducibleMediaTypes(); + if (!mediaTypes.isEmpty()) { + exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes); + } } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index 8c0c3a4f3690..362f98314855 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -148,9 +148,12 @@ protected void handleMatch(RequestMappingInfo info, String lookupPath, HttpServl extractMatchDetails((PatternsRequestCondition) condition, lookupPath, request); } - if (!info.getProducesCondition().getProducibleMediaTypes().isEmpty()) { - Set mediaTypes = info.getProducesCondition().getProducibleMediaTypes(); - request.setAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes); + ProducesRequestCondition producesCondition = info.getProducesCondition(); + if (!producesCondition.isEmpty()) { + Set mediaTypes = producesCondition.getProducibleMediaTypes(); + if (!mediaTypes.isEmpty()) { + request.setAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes); + } } }