Initialize pre-filled HashMaps with large enough capacity
Empty Maps are preferably initialized without capacity (not initializing them at all or lazily initializing with default capacity when needed). Issue: SPR-17105
This commit is contained in:
parent
457d586859
commit
4a147d26fc
|
|
@ -43,7 +43,7 @@ import org.springframework.util.ObjectUtils;
|
|||
*/
|
||||
public class ConstructorArgumentValues {
|
||||
|
||||
private final Map<Integer, ValueHolder> indexedArgumentValues = new LinkedHashMap<>(0);
|
||||
private final Map<Integer, ValueHolder> indexedArgumentValues = new LinkedHashMap<>();
|
||||
|
||||
private final List<ValueHolder> genericArgumentValues = new ArrayList<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
|||
|
||||
private boolean primary = false;
|
||||
|
||||
private final Map<String, AutowireCandidateQualifier> qualifiers = new LinkedHashMap<>(0);
|
||||
private final Map<String, AutowireCandidateQualifier> qualifiers = new LinkedHashMap<>();
|
||||
|
||||
@Nullable
|
||||
private Supplier<?> instanceSupplier;
|
||||
|
|
|
|||
|
|
@ -410,7 +410,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
Object cacheValue;
|
||||
Object returnValue;
|
||||
|
||||
if (cacheHit != null && cachePutRequests.isEmpty() && !hasCachePut(contexts)) {
|
||||
if (cacheHit != null && !hasCachePut(contexts)) {
|
||||
// If there are no put requests, just use the cache hit
|
||||
cacheValue = cacheHit.get();
|
||||
returnValue = wrapCacheValue(method, cacheValue);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -230,17 +230,21 @@ public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, Sche
|
|||
protected static class ManagedTaskBuilder {
|
||||
|
||||
public static Runnable buildManagedTask(Runnable task, String identityName) {
|
||||
Map<String, String> properties = new HashMap<>(2);
|
||||
Map<String, String> properties;
|
||||
if (task instanceof SchedulingAwareRunnable) {
|
||||
properties = new HashMap<>(4);
|
||||
properties.put(ManagedTask.LONGRUNNING_HINT,
|
||||
Boolean.toString(((SchedulingAwareRunnable) task).isLongLived()));
|
||||
}
|
||||
else {
|
||||
properties = new HashMap<>(2);
|
||||
}
|
||||
properties.put(ManagedTask.IDENTITY_NAME, identityName);
|
||||
return ManagedExecutors.managedTask(task, properties, null);
|
||||
}
|
||||
|
||||
public static <T> Callable<T> buildManagedTask(Callable<T> task, String identityName) {
|
||||
Map<String, String> properties = new HashMap<>(1);
|
||||
Map<String, String> properties = new HashMap<>(2);
|
||||
properties.put(ManagedTask.IDENTITY_NAME, identityName);
|
||||
return ManagedExecutors.managedTask(task, properties, null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
|
|||
|
||||
private final List<ObjectError> errors = new LinkedList<>();
|
||||
|
||||
private final Map<String, Class<?>> fieldTypes = new HashMap<>(0);
|
||||
private final Map<String, Class<?>> fieldTypes = new HashMap<>();
|
||||
|
||||
private final Map<String, Object> fieldValues = new HashMap<>(0);
|
||||
private final Map<String, Object> fieldValues = new HashMap<>();
|
||||
|
||||
private final Set<String> suppressedFields = new HashSet<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
|
|||
public abstract class AttributeAccessorSupport implements AttributeAccessor, Serializable {
|
||||
|
||||
/** Map with String keys and Object values. */
|
||||
private final Map<String, Object> attributes = new LinkedHashMap<>(0);
|
||||
private final Map<String, Object> attributes = new LinkedHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -465,7 +465,7 @@ public abstract class AbstractJdbcInsert {
|
|||
if (keyQuery.toUpperCase().startsWith("RETURNING")) {
|
||||
Long key = getJdbcTemplate().queryForObject(
|
||||
getInsertString() + " " + keyQuery, values.toArray(), Long.class);
|
||||
Map<String, Object> keys = new HashMap<>(1);
|
||||
Map<String, Object> keys = new HashMap<>(2);
|
||||
keys.put(getGeneratedKeyNames()[0], key);
|
||||
keyHolder.getKeyList().add(keys);
|
||||
}
|
||||
|
|
@ -484,7 +484,7 @@ public abstract class AbstractJdbcInsert {
|
|||
//Get the key
|
||||
Statement keyStmt = null;
|
||||
ResultSet rs = null;
|
||||
Map<String, Object> keys = new HashMap<>(1);
|
||||
Map<String, Object> keys = new HashMap<>(2);
|
||||
try {
|
||||
keyStmt = con.createStatement();
|
||||
rs = keyStmt.executeQuery(keyQuery);
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
|
|||
* @param keysToIgnore the keys of the entries to ignore
|
||||
*/
|
||||
private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) {
|
||||
this.headers = new HashMap<>(original.headers.size() - keysToIgnore.size());
|
||||
this.headers = new HashMap<>(original.headers.size());
|
||||
original.headers.forEach((key, value) -> {
|
||||
if (!keysToIgnore.contains(key)) {
|
||||
this.headers.put(key, value);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -38,7 +38,7 @@ import org.springframework.util.MultiValueMap;
|
|||
public abstract class AbstractSubscriptionRegistry implements SubscriptionRegistry {
|
||||
|
||||
private static final MultiValueMap<String, String> EMPTY_MAP =
|
||||
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0));
|
||||
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>());
|
||||
|
||||
protected final Log logger = SimpLogging.forLogName(getClass());
|
||||
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC
|
|||
if (handler == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, MessageHandler> subscriptions = new HashMap<>(1);
|
||||
Map<String, MessageHandler> subscriptions = new HashMap<>(4);
|
||||
String destination = getBrokerRegistry().getUserDestinationBroadcast();
|
||||
if (destination != null) {
|
||||
subscriptions.put(destination, userDestinationMessageHandler());
|
||||
|
|
|
|||
|
|
@ -545,7 +545,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||
private class SessionLookup {
|
||||
|
||||
public Map<String, SimpSession> findSessions(String userName) {
|
||||
Map<String, SimpSession> map = new HashMap<>(1);
|
||||
Map<String, SimpSession> map = new HashMap<>(4);
|
||||
SimpUser user = localRegistry.getUser(userName);
|
||||
if (user != null) {
|
||||
for (SimpSession session : user.getSessions()) {
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||
/**
|
||||
* The empty {@code HttpHeaders} instance (immutable).
|
||||
*/
|
||||
public static final HttpHeaders EMPTY = new HttpHeaders(new LinkedHashMap<>(0), true);
|
||||
public static final HttpHeaders EMPTY = new HttpHeaders(new LinkedHashMap<>(), true);
|
||||
/**
|
||||
* The HTTP {@code Accept} header field name.
|
||||
* @see <a href="http://tools.ietf.org/html/rfc7231#section-5.3.2">Section 5.3.2 of RFC 7231</a>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
|
@ -35,7 +35,7 @@ public enum HttpMethod {
|
|||
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE;
|
||||
|
||||
|
||||
private static final Map<String, HttpMethod> mappings = new HashMap<>(8);
|
||||
private static final Map<String, HttpMethod> mappings = new HashMap<>(16);
|
||||
|
||||
static {
|
||||
for (HttpMethod httpMethod : values()) {
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
final class DefaultPathContainer implements PathContainer {
|
||||
|
||||
private static final MultiValueMap<String, String> EMPTY_MAP = new LinkedMultiValueMap<>(0);
|
||||
private static final MultiValueMap<String, String> EMPTY_MAP = new LinkedMultiValueMap<>();
|
||||
|
||||
private static final PathContainer EMPTY_PATH = new DefaultPathContainer("", Collections.emptyList());
|
||||
|
||||
|
|
|
|||
|
|
@ -55,54 +55,46 @@ final class HierarchicalUriComponents extends UriComponents {
|
|||
|
||||
private static final String PATH_DELIMITER_STRING = "/";
|
||||
|
||||
private static final MultiValueMap<String, String> EMPTY_QUERY_PARAMS =
|
||||
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>());
|
||||
|
||||
|
||||
/**
|
||||
* Represents an empty path.
|
||||
*/
|
||||
static final PathComponent NULL_PATH_COMPONENT = new PathComponent() {
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPathSegments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathComponent encode(BiFunction<String, Type, String> encoder) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathComponent expand(UriTemplateVariables uriVariables, @Nullable UnaryOperator<String> encoder) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyToUriComponentsBuilder(UriComponentsBuilder builder) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (this == other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getClass().hashCode();
|
||||
}
|
||||
};
|
||||
|
||||
private static final MultiValueMap<String, String> EMPTY_QUERY_PARAMS =
|
||||
CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(0));
|
||||
|
||||
|
||||
@Nullable
|
||||
private final String userInfo;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class HtmlCharacterEntityReferences {
|
|||
|
||||
private final String[] characterToEntityReferenceMap = new String[3000];
|
||||
|
||||
private final Map<String, Character> entityReferenceToCharacterMap = new HashMap<>(252);
|
||||
private final Map<String, Character> entityReferenceToCharacterMap = new HashMap<>(512);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.springframework.util.ObjectUtils;
|
|||
@SuppressWarnings("serial")
|
||||
final class OpaqueUriComponents extends UriComponents {
|
||||
|
||||
private static final MultiValueMap<String, String> QUERY_PARAMS_NONE = new LinkedMultiValueMap<>(0);
|
||||
private static final MultiValueMap<String, String> QUERY_PARAMS_NONE = new LinkedMultiValueMap<>();
|
||||
|
||||
@Nullable
|
||||
private final String ssp;
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ class DefaultWebClient implements WebClient {
|
|||
|
||||
private MultiValueMap<String, String> initCookies() {
|
||||
if (CollectionUtils.isEmpty(this.cookies)) {
|
||||
return (defaultCookies != null ? defaultCookies : new LinkedMultiValueMap<>(0));
|
||||
return (defaultCookies != null ? defaultCookies : new LinkedMultiValueMap<>());
|
||||
}
|
||||
else if (CollectionUtils.isEmpty(defaultCookies)) {
|
||||
return this.cookies;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.reactive.socket.adapter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -49,14 +50,14 @@ public abstract class NettyWebSocketSessionSupport<T> extends AbstractWebSocketS
|
|||
protected static final int DEFAULT_FRAME_MAX_SIZE = 64 * 1024;
|
||||
|
||||
|
||||
private static final Map<Class<?>, WebSocketMessage.Type> MESSAGE_TYPES;
|
||||
private static final Map<Class<?>, WebSocketMessage.Type> messageTypes;
|
||||
|
||||
static {
|
||||
MESSAGE_TYPES = new HashMap<>(4);
|
||||
MESSAGE_TYPES.put(TextWebSocketFrame.class, WebSocketMessage.Type.TEXT);
|
||||
MESSAGE_TYPES.put(BinaryWebSocketFrame.class, WebSocketMessage.Type.BINARY);
|
||||
MESSAGE_TYPES.put(PingWebSocketFrame.class, WebSocketMessage.Type.PING);
|
||||
MESSAGE_TYPES.put(PongWebSocketFrame.class, WebSocketMessage.Type.PONG);
|
||||
messageTypes = new HashMap<>(8);
|
||||
messageTypes.put(TextWebSocketFrame.class, WebSocketMessage.Type.TEXT);
|
||||
messageTypes.put(BinaryWebSocketFrame.class, WebSocketMessage.Type.BINARY);
|
||||
messageTypes.put(PingWebSocketFrame.class, WebSocketMessage.Type.PING);
|
||||
messageTypes.put(PongWebSocketFrame.class, WebSocketMessage.Type.PONG);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -73,7 +74,7 @@ public abstract class NettyWebSocketSessionSupport<T> extends AbstractWebSocketS
|
|||
|
||||
protected WebSocketMessage toMessage(WebSocketFrame frame) {
|
||||
DataBuffer payload = bufferFactory().wrap(frame.content());
|
||||
return new WebSocketMessage(MESSAGE_TYPES.get(frame.getClass()), payload);
|
||||
return new WebSocketMessage(messageTypes.get(frame.getClass()), payload);
|
||||
}
|
||||
|
||||
protected WebSocketFrame toFrame(WebSocketMessage message) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue