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

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 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.
@@ -52,7 +52,7 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
@Nullable
private String targetRequestPath;
private final MultiValueMap<String, String> targetRequestParams = new LinkedMultiValueMap<>(4);
private final MultiValueMap<String, String> targetRequestParams = new LinkedMultiValueMap<>(3);
private long expirationTime = -1;

View File

@@ -17,10 +17,10 @@
package org.springframework.web.servlet.config.annotation;
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;
/**
@@ -56,7 +56,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

@@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.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;
@@ -30,6 +29,7 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
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.CorsUtils;
@@ -48,7 +48,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
private static final Map<String, RequestMethodsRequestCondition> requestMethodConditionCache;
static {
requestMethodConditionCache = new HashMap<>(RequestMethod.values().length);
requestMethodConditionCache = CollectionUtils.newHashMap(RequestMethod.values().length);
for (RequestMethod method : RequestMethod.values()) {
requestMethodConditionCache.put(method.name(), new RequestMethodsRequestCondition(method));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@@ -332,7 +332,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
size += (model != null ? model.size() : 0);
size += (pathVars != null ? pathVars.size() : 0);
Map<String, Object> mergedModel = new LinkedHashMap<>(size);
Map<String, Object> mergedModel = CollectionUtils.newLinkedHashMap(size);
mergedModel.putAll(this.staticAttributes);
if (pathVars != null) {
mergedModel.putAll(pathVars);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.servlet.view.json;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -155,7 +154,7 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
*/
@Override
protected Object filterModel(Map<String, Object> model) {
Map<String, Object> result = new HashMap<>(model.size());
Map<String, Object> result = CollectionUtils.newHashMap(model.size());
Set<String> modelKeys = (!CollectionUtils.isEmpty(this.modelKeys) ? this.modelKeys : model.keySet());
model.forEach((clazz, value) -> {
if (!(value instanceof BindingResult) && modelKeys.contains(clazz) &&