From fce58c6a6efb75cf2a29718597b2ae6b64f1dc6d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 8 Apr 2019 18:51:38 +0200 Subject: [PATCH] Efficient MultiValueMap.entrySet() iteration in decodeMatrixVariables --- .../web/util/UrlPathHelper.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java index 789ed409c24..153c0981c2b 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java +++ b/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java @@ -19,6 +19,7 @@ package org.springframework.web.util; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import javax.servlet.http.HttpServletRequest; @@ -494,7 +495,7 @@ public class UrlPathHelper { /** * Remove ";" (semicolon) content from the given request URI if the - * {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent} + * {@linkplain #setRemoveSemicolonContent removeSemicolonContent} * property is set to "true". Note that "jssessionid" is always removed. * @param requestUri the request URI string to remove ";" content from * @return the updated URI string @@ -526,12 +527,10 @@ public class UrlPathHelper { } /** - * Decode the given URI path variables via - * {@link #decodeRequestString(HttpServletRequest, String)} unless - * {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is - * assumed the URL path from which the variables were extracted is already - * decoded through a call to - * {@link #getLookupPathForRequest(HttpServletRequest)}. + * Decode the given URI path variables via {@link #decodeRequestString} unless + * {@link #setUrlDecode} is set to {@code true} in which case it is assumed + * the URL path from which the variables were extracted is already decoded + * through a call to {@link #getLookupPathForRequest(HttpServletRequest)}. * @param request current HTTP request * @param vars URI variables extracted from the URL path * @return the same Map or a new Map instance @@ -550,25 +549,25 @@ public class UrlPathHelper { } /** - * Decode the given matrix variables via - * {@link #decodeRequestString(HttpServletRequest, String)} unless - * {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is - * assumed the URL path from which the variables were extracted is already - * decoded through a call to - * {@link #getLookupPathForRequest(HttpServletRequest)}. + * Decode the given matrix variables via {@link #decodeRequestString} unless + * {@link #setUrlDecode} is set to {@code true} in which case it is assumed + * the URL path from which the variables were extracted is already decoded + * through a call to {@link #getLookupPathForRequest(HttpServletRequest)}. * @param request current HTTP request * @param vars URI variables extracted from the URL path * @return the same Map or a new Map instance */ - public MultiValueMap decodeMatrixVariables(HttpServletRequest request, MultiValueMap vars) { + public MultiValueMap decodeMatrixVariables( + HttpServletRequest request, MultiValueMap vars) { + if (this.urlDecode) { return vars; } else { - MultiValueMap decodedVars = new LinkedMultiValueMap (vars.size()); - for (String key : vars.keySet()) { - for (String value : vars.get(key)) { - decodedVars.add(key, decodeInternal(request, value)); + MultiValueMap decodedVars = new LinkedMultiValueMap(vars.size()); + for (Map.Entry> entry : vars.entrySet()) { + for (String value : entry.getValue()) { + decodedVars.add(entry.getKey(), decodeInternal(request, value)); } } return decodedVars;