Avoid resizing of fixed-size HashMap/LinkedHashMap variants

Closes gh-25349
This commit is contained in:
Juergen Hoeller
2020-08-25 19:26:18 +02:00
parent 241afeb1b7
commit ff11467a0c
58 changed files with 195 additions and 149 deletions

View File

@@ -17,10 +17,10 @@
package org.springframework.web.reactive.config;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration;
/**
@@ -55,7 +55,7 @@ public class CorsRegistry {
* keyed by path pattern.
*/
protected Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
Map<String, CorsConfiguration> configs = CollectionUtils.newLinkedHashMap(this.registrations.size());
for (CorsRegistration registration : this.registrations) {
configs.put(registration.getPathPattern(), registration.getCorsConfiguration());
}

View File

@@ -212,7 +212,7 @@ class DefaultWebClient implements WebClient {
private MultiValueMap<String, String> getCookies() {
if (this.cookies == null) {
this.cookies = new LinkedMultiValueMap<>(4);
this.cookies = new LinkedMultiValueMap<>(3);
}
return this.cookies;
}

View File

@@ -180,7 +180,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
private MultiValueMap<String, String> initCookies() {
if (this.defaultCookies == null) {
this.defaultCookies = new LinkedMultiValueMap<>(4);
this.defaultCookies = new LinkedMultiValueMap<>(3);
}
return this.defaultCookies;
}

View File

@@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.condition;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@@ -27,6 +26,7 @@ import java.util.Set;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.cors.reactive.CorsUtils;
@@ -45,7 +45,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
private static final Map<HttpMethod, RequestMethodsRequestCondition> requestMethodConditionCache;
static {
requestMethodConditionCache = new HashMap<>(RequestMethod.values().length);
requestMethodConditionCache = CollectionUtils.newHashMap(RequestMethod.values().length);
for (RequestMethod method : RequestMethod.values()) {
requestMethodConditionCache.put(
HttpMethod.valueOf(method.name()), new RequestMethodsRequestCondition(method));