Skip to content

Commit fce58c6

Browse files
committed
Efficient MultiValueMap.entrySet() iteration in decodeMatrixVariables
1 parent 54dd833 commit fce58c6

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.UnsupportedEncodingException;
2020
import java.net.URLDecoder;
2121
import java.util.LinkedHashMap;
22+
import java.util.List;
2223
import java.util.Map;
2324
import java.util.Properties;
2425
import javax.servlet.http.HttpServletRequest;
@@ -494,7 +495,7 @@ protected String determineEncoding(HttpServletRequest request) {
494495

495496
/**
496497
* Remove ";" (semicolon) content from the given request URI if the
497-
* {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
498+
* {@linkplain #setRemoveSemicolonContent removeSemicolonContent}
498499
* property is set to "true". Note that "jssessionid" is always removed.
499500
* @param requestUri the request URI string to remove ";" content from
500501
* @return the updated URI string
@@ -526,12 +527,10 @@ private String removeJsessionid(String requestUri) {
526527
}
527528

528529
/**
529-
* Decode the given URI path variables via
530-
* {@link #decodeRequestString(HttpServletRequest, String)} unless
531-
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
532-
* assumed the URL path from which the variables were extracted is already
533-
* decoded through a call to
534-
* {@link #getLookupPathForRequest(HttpServletRequest)}.
530+
* Decode the given URI path variables via {@link #decodeRequestString} unless
531+
* {@link #setUrlDecode} is set to {@code true} in which case it is assumed
532+
* the URL path from which the variables were extracted is already decoded
533+
* through a call to {@link #getLookupPathForRequest(HttpServletRequest)}.
535534
* @param request current HTTP request
536535
* @param vars URI variables extracted from the URL path
537536
* @return the same Map or a new Map instance
@@ -550,25 +549,25 @@ public Map<String, String> decodePathVariables(HttpServletRequest request, Map<S
550549
}
551550

552551
/**
553-
* Decode the given matrix variables via
554-
* {@link #decodeRequestString(HttpServletRequest, String)} unless
555-
* {@link #setUrlDecode(boolean)} is set to {@code true} in which case it is
556-
* assumed the URL path from which the variables were extracted is already
557-
* decoded through a call to
558-
* {@link #getLookupPathForRequest(HttpServletRequest)}.
552+
* Decode the given matrix variables via {@link #decodeRequestString} unless
553+
* {@link #setUrlDecode} is set to {@code true} in which case it is assumed
554+
* the URL path from which the variables were extracted is already decoded
555+
* through a call to {@link #getLookupPathForRequest(HttpServletRequest)}.
559556
* @param request current HTTP request
560557
* @param vars URI variables extracted from the URL path
561558
* @return the same Map or a new Map instance
562559
*/
563-
public MultiValueMap<String, String> decodeMatrixVariables(HttpServletRequest request, MultiValueMap<String, String> vars) {
560+
public MultiValueMap<String, String> decodeMatrixVariables(
561+
HttpServletRequest request, MultiValueMap<String, String> vars) {
562+
564563
if (this.urlDecode) {
565564
return vars;
566565
}
567566
else {
568-
MultiValueMap<String, String> decodedVars = new LinkedMultiValueMap <String, String>(vars.size());
569-
for (String key : vars.keySet()) {
570-
for (String value : vars.get(key)) {
571-
decodedVars.add(key, decodeInternal(request, value));
567+
MultiValueMap<String, String> decodedVars = new LinkedMultiValueMap<String, String>(vars.size());
568+
for (Map.Entry<String, List<String>> entry : vars.entrySet()) {
569+
for (String value : entry.getValue()) {
570+
decodedVars.add(entry.getKey(), decodeInternal(request, value));
572571
}
573572
}
574573
return decodedVars;

0 commit comments

Comments
 (0)