From 4486ab1cb7d0ea915803b17251b2889c5a5320bc Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Wed, 7 Feb 2024 11:23:48 -0800 Subject: [PATCH] Initialize Map with correct size in RequestPredicates Fix another instance where a LinkedHashMap was initialized with an initial capacity that would always cause a resize / rehash to occur. Switch to CollectionUtils.newLinkedHashMap to size the map appropiately for the expected number of items. Closes gh-32215 --- .../springframework/web/servlet/function/RequestPredicates.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java index 890cf5f623..0523bccbc9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java @@ -1237,7 +1237,7 @@ public abstract class RequestPredicates { PathPattern oldPathPattern = (PathPattern) request.attribute(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE) .orElse(null); - Map result = new LinkedHashMap<>(2); + Map result = CollectionUtils.newLinkedHashMap(2); result.put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, mergeMaps(oldPathVariables, newPathVariables)); result.put(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE, mergePatterns(oldPathPattern, newPathPattern)); return result;