Avoid resizing of fixed-size HashMap/LinkedHashMap variants
Closes gh-25349
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.r2dbc.connection.lookup;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.r2dbc.spi.Connection;
|
||||
@@ -27,6 +26,7 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Abstract {@link ConnectionFactory} implementation that routes
|
||||
@@ -129,12 +129,12 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact
|
||||
this.connectionFactoryLookup = connectionFactoryLookup;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
Assert.notNull(this.targetConnectionFactories, "Property 'targetConnectionFactories' must not be null");
|
||||
|
||||
this.resolvedConnectionFactories = new HashMap<>(this.targetConnectionFactories.size());
|
||||
this.resolvedConnectionFactories = CollectionUtils.newHashMap(this.targetConnectionFactories.size());
|
||||
this.targetConnectionFactories.forEach((key, value) -> {
|
||||
Object lookupKey = resolveSpecifiedLookupKey(key);
|
||||
ConnectionFactory connectionFactory = resolveSpecifiedConnectionFactory(value);
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.springframework.r2dbc.connection.ConnectionFactoryUtils;
|
||||
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
|
||||
import org.springframework.r2dbc.core.binding.BindTarget;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -255,7 +256,6 @@ class DefaultDatabaseClient implements DatabaseClient {
|
||||
"Value at index %d must not be null. Use bindNull(…) instead.", index));
|
||||
|
||||
Map<Integer, Parameter> byIndex = new LinkedHashMap<>(this.byIndex);
|
||||
|
||||
if (value instanceof Parameter) {
|
||||
byIndex.put(index, (Parameter) value);
|
||||
}
|
||||
@@ -285,7 +285,6 @@ class DefaultDatabaseClient implements DatabaseClient {
|
||||
"Value for parameter %s must not be null. Use bindNull(…) instead.", name));
|
||||
|
||||
Map<String, Parameter> byName = new LinkedHashMap<>(this.byName);
|
||||
|
||||
if (value instanceof Parameter) {
|
||||
byName.put(name, (Parameter) value);
|
||||
}
|
||||
@@ -393,7 +392,7 @@ class DefaultDatabaseClient implements DatabaseClient {
|
||||
private MapBindParameterSource retrieveParameters(String sql, List<String> parameterNames,
|
||||
Map<String, Parameter> remainderByName, Map<Integer, Parameter> remainderByIndex) {
|
||||
|
||||
Map<String, Parameter> namedBindings = new LinkedHashMap<>(parameterNames.size());
|
||||
Map<String, Parameter> namedBindings = CollectionUtils.newLinkedHashMap(parameterNames.size());
|
||||
for (String parameterName : parameterNames) {
|
||||
Parameter parameter = getParameter(remainderByName, remainderByIndex, parameterNames, parameterName);
|
||||
if (parameter == null) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Spliterator;
|
||||
@@ -31,6 +30,7 @@ import io.r2dbc.spi.Statement;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Value object representing value and {@code null} bindings
|
||||
@@ -60,7 +60,7 @@ public class Bindings implements Iterable<Bindings.Binding> {
|
||||
*/
|
||||
public Bindings(Collection<Binding> bindings) {
|
||||
Assert.notNull(bindings, "Bindings must not be null");
|
||||
Map<BindMarker, Binding> mapping = new LinkedHashMap<>(bindings.size());
|
||||
Map<BindMarker, Binding> mapping = CollectionUtils.newLinkedHashMap(bindings.size());
|
||||
bindings.forEach(binding -> mapping.put(binding.getBindMarker(), binding));
|
||||
this.bindings = mapping;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user