Avoid resizing of fixed-size HashMap/LinkedHashMap variants
Closes gh-25349
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.web.reactive.function.server;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -31,6 +30,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.result.view.View;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
@@ -103,7 +103,7 @@ class RenderingResponseIntegrationTests extends AbstractRouterFunctionIntegratio
|
||||
|
||||
private Map<String, String> parseBody(String body) {
|
||||
String[] lines = body.split("\\n");
|
||||
Map<String, String> result = new LinkedHashMap<>(lines.length);
|
||||
Map<String, String> result = CollectionUtils.newLinkedHashMap(lines.length);
|
||||
for (String line : lines) {
|
||||
int idx = line.indexOf('=');
|
||||
String key = line.substring(0, idx);
|
||||
|
||||
Reference in New Issue
Block a user