Replace remaining usage of LinkedList with ArrayList/ArrayDeque
Closes gh-25650
This commit is contained in:
@@ -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.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.core;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -36,7 +36,7 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscoverer {
|
||||
|
||||
private final List<ParameterNameDiscoverer> parameterNameDiscoverers = new LinkedList<>();
|
||||
private final List<ParameterNameDiscoverer> parameterNameDiscoverers = new ArrayList<>(2);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -651,7 +652,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
*/
|
||||
private static class ConvertersForPair {
|
||||
|
||||
private final LinkedList<GenericConverter> converters = new LinkedList<>();
|
||||
private final Deque<GenericConverter> converters = new ArrayDeque<>(1);
|
||||
|
||||
public void add(GenericConverter converter) {
|
||||
this.converters.addFirst(converter);
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -655,7 +655,7 @@ public class AntPathMatcher implements PathMatcher {
|
||||
@Nullable
|
||||
private final Pattern pattern;
|
||||
|
||||
private final List<String> variableNames = new LinkedList<>();
|
||||
private final List<String> variableNames = new ArrayList<>();
|
||||
|
||||
public AntPathStringMatcher(String pattern) {
|
||||
this(pattern, true);
|
||||
|
||||
@@ -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.
|
||||
@@ -20,8 +20,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -50,7 +51,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
||||
|
||||
|
||||
// The buffers used to store the content bytes
|
||||
private final LinkedList<byte[]> buffers = new LinkedList<>();
|
||||
private final Deque<byte[]> buffers = new ArrayDeque<>();
|
||||
|
||||
// The size, in bytes, to use when allocating the first byte[]
|
||||
private final int initialBlockSize;
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
package org.springframework.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple implementation of {@link MultiValueMap} that wraps a {@link LinkedHashMap},
|
||||
* storing multiple values in a {@link LinkedList}.
|
||||
* storing multiple values in an {@link ArrayList}.
|
||||
*
|
||||
* <p>This Map implementation is generally not thread-safe. It is primarily designed
|
||||
* for data structures exposed from request objects, for use in a single thread only.
|
||||
@@ -75,7 +75,7 @@ public class LinkedMultiValueMap<K, V> extends MultiValueMapAdapter<K, V> implem
|
||||
/**
|
||||
* Create a deep copy of this Map.
|
||||
* @return a copy of this Map, including a copy of each value-holding List entry
|
||||
* (consistently using an independent modifiable {@link LinkedList} for each entry)
|
||||
* (consistently using an independent modifiable {@link ArrayList} for each entry)
|
||||
* along the lines of {@code MultiValueMap.addAll} semantics
|
||||
* @since 4.2
|
||||
* @see #addAll(MultiValueMap)
|
||||
@@ -83,7 +83,7 @@ public class LinkedMultiValueMap<K, V> extends MultiValueMapAdapter<K, V> implem
|
||||
*/
|
||||
public LinkedMultiValueMap<K, V> deepCopy() {
|
||||
LinkedMultiValueMap<K, V> copy = new LinkedMultiValueMap<>(size());
|
||||
forEach((key, values) -> copy.put(key, new LinkedList<>(values)));
|
||||
forEach((key, values) -> copy.put(key, new ArrayList<>(values)));
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.springframework.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -56,13 +56,13 @@ class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
|
||||
|
||||
@Override
|
||||
public void add(K key, @Nullable V value) {
|
||||
List<V> values = this.targetMap.computeIfAbsent(key, k -> new LinkedList<>());
|
||||
List<V> values = this.targetMap.computeIfAbsent(key, k -> new ArrayList<>(1));
|
||||
values.add(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAll(K key, List<? extends V> values) {
|
||||
List<V> currentValues = this.targetMap.computeIfAbsent(key, k -> new LinkedList<>());
|
||||
List<V> currentValues = this.targetMap.computeIfAbsent(key, k -> new ArrayList<>(1));
|
||||
currentValues.addAll(values);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
|
||||
|
||||
@Override
|
||||
public void set(K key, @Nullable V value) {
|
||||
List<V> values = new LinkedList<>();
|
||||
List<V> values = new ArrayList<>(1);
|
||||
values.add(value);
|
||||
this.targetMap.put(key, values);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.util;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class StopWatch {
|
||||
|
||||
private boolean keepTaskList = true;
|
||||
|
||||
private final List<TaskInfo> taskList = new LinkedList<>();
|
||||
private final List<TaskInfo> taskList = new ArrayList<>(1);
|
||||
|
||||
/** Start time of the current task. */
|
||||
private long startTimeNanos;
|
||||
|
||||
@@ -18,14 +18,15 @@ package org.springframework.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
@@ -693,7 +694,7 @@ public abstract class StringUtils {
|
||||
}
|
||||
|
||||
String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR);
|
||||
LinkedList<String> pathElements = new LinkedList<>();
|
||||
Deque<String> pathElements = new ArrayDeque<>();
|
||||
int tops = 0;
|
||||
|
||||
for (int i = pathArray.length - 1; i >= 0; i--) {
|
||||
@@ -712,7 +713,7 @@ public abstract class StringUtils {
|
||||
}
|
||||
else {
|
||||
// Normal path element found.
|
||||
pathElements.add(0, element);
|
||||
pathElements.addFirst(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,11 +724,11 @@ public abstract class StringUtils {
|
||||
}
|
||||
// Remaining top paths need to be retained.
|
||||
for (int i = 0; i < tops; i++) {
|
||||
pathElements.add(0, TOP_PATH);
|
||||
pathElements.addFirst(TOP_PATH);
|
||||
}
|
||||
// If nothing else left, at least explicitly point to current path.
|
||||
if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) {
|
||||
pathElements.add(0, CURRENT_PATH);
|
||||
pathElements.addFirst(CURRENT_PATH);
|
||||
}
|
||||
|
||||
return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR);
|
||||
|
||||
@@ -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.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.util.concurrent;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -36,9 +36,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class ListenableFutureCallbackRegistry<T> {
|
||||
|
||||
private final Queue<SuccessCallback<? super T>> successCallbacks = new LinkedList<>();
|
||||
private final Queue<SuccessCallback<? super T>> successCallbacks = new ArrayDeque<>(1);
|
||||
|
||||
private final Queue<FailureCallback> failureCallbacks = new LinkedList<>();
|
||||
private final Queue<FailureCallback> failureCallbacks = new ArrayDeque<>(1);
|
||||
|
||||
private State state = State.NEW;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user